HDFS-15219: use a monitor object to control the execution of the RolloverSignerSecretProvider internal thread
This commit is contained in:
parent
164a0a2410
commit
03c1cbb676
|
@ -20,7 +20,7 @@ public class TestRolloverSignerSecretProvider {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetAndRollSecrets() throws Exception {
|
public void testGetAndRollSecrets() throws Exception {
|
||||||
long rolloverFrequency = 5 * 1000; // rollover every 5 sec
|
long rolloverFrequency = 2 * 1000; // rollover every 2 sec
|
||||||
byte[] secret1 = "doctor".getBytes();
|
byte[] secret1 = "doctor".getBytes();
|
||||||
byte[] secret2 = "who".getBytes();
|
byte[] secret2 = "who".getBytes();
|
||||||
byte[] secret3 = "tardis".getBytes();
|
byte[] secret3 = "tardis".getBytes();
|
||||||
|
@ -36,7 +36,9 @@ public class TestRolloverSignerSecretProvider {
|
||||||
Assert.assertEquals(2, allSecrets.length);
|
Assert.assertEquals(2, allSecrets.length);
|
||||||
Assert.assertArrayEquals(secret1, allSecrets[0]);
|
Assert.assertArrayEquals(secret1, allSecrets[0]);
|
||||||
Assert.assertNull(allSecrets[1]);
|
Assert.assertNull(allSecrets[1]);
|
||||||
Thread.sleep(rolloverFrequency + 2000);
|
synchronized (secretProvider.monitor){
|
||||||
|
secretProvider.monitor.wait();
|
||||||
|
}
|
||||||
|
|
||||||
currentSecret = secretProvider.getCurrentSecret();
|
currentSecret = secretProvider.getCurrentSecret();
|
||||||
allSecrets = secretProvider.getAllSecrets();
|
allSecrets = secretProvider.getAllSecrets();
|
||||||
|
@ -44,7 +46,9 @@ public class TestRolloverSignerSecretProvider {
|
||||||
Assert.assertEquals(2, allSecrets.length);
|
Assert.assertEquals(2, allSecrets.length);
|
||||||
Assert.assertArrayEquals(secret2, allSecrets[0]);
|
Assert.assertArrayEquals(secret2, allSecrets[0]);
|
||||||
Assert.assertArrayEquals(secret1, allSecrets[1]);
|
Assert.assertArrayEquals(secret1, allSecrets[1]);
|
||||||
Thread.sleep(rolloverFrequency + 2000);
|
synchronized (secretProvider.monitor){
|
||||||
|
secretProvider.monitor.wait();
|
||||||
|
}
|
||||||
|
|
||||||
currentSecret = secretProvider.getCurrentSecret();
|
currentSecret = secretProvider.getCurrentSecret();
|
||||||
allSecrets = secretProvider.getAllSecrets();
|
allSecrets = secretProvider.getAllSecrets();
|
||||||
|
@ -61,9 +65,9 @@ public class TestRolloverSignerSecretProvider {
|
||||||
|
|
||||||
private byte[][] newSecretSequence;
|
private byte[][] newSecretSequence;
|
||||||
private int newSecretSequenceIndex;
|
private int newSecretSequenceIndex;
|
||||||
|
final Object monitor = new Object();
|
||||||
|
|
||||||
public TRolloverSignerSecretProvider(byte[][] newSecretSequence)
|
TRolloverSignerSecretProvider(byte[][] newSecretSequence) {
|
||||||
throws Exception {
|
|
||||||
super();
|
super();
|
||||||
this.newSecretSequence = newSecretSequence;
|
this.newSecretSequence = newSecretSequence;
|
||||||
this.newSecretSequenceIndex = 0;
|
this.newSecretSequenceIndex = 0;
|
||||||
|
@ -71,6 +75,9 @@ public class TestRolloverSignerSecretProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected byte[] generateNewSecret() {
|
protected byte[] generateNewSecret() {
|
||||||
|
synchronized (monitor){
|
||||||
|
monitor.notify();
|
||||||
|
}
|
||||||
return newSecretSequence[newSecretSequenceIndex++];
|
return newSecretSequence[newSecretSequenceIndex++];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue