mirror of https://github.com/apache/druid.git
Try and make AnnouncerTest a bit more predictable
This commit is contained in:
parent
e5b3226b62
commit
7d635a2ce2
|
@ -56,10 +56,11 @@ public class AnnouncerTest extends CuratorTestBase
|
||||||
tearDownServerAndCurator();
|
tearDownServerAndCurator();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(timeout = 60_000L)
|
||||||
public void testSanity() throws Exception
|
public void testSanity() throws Exception
|
||||||
{
|
{
|
||||||
curator.start();
|
curator.start();
|
||||||
|
curator.blockUntilConnected();
|
||||||
Announcer announcer = new Announcer(curator, exec);
|
Announcer announcer = new Announcer(curator, exec);
|
||||||
|
|
||||||
final byte[] billy = "billy".getBytes();
|
final byte[] billy = "billy".getBytes();
|
||||||
|
@ -72,50 +73,66 @@ public class AnnouncerTest extends CuratorTestBase
|
||||||
|
|
||||||
announcer.start();
|
announcer.start();
|
||||||
|
|
||||||
Assert.assertArrayEquals("/test1 has data", billy, curator.getData().decompressed().forPath(testPath1));
|
try {
|
||||||
Assert.assertNull("/somewhere/test2 still does not exist", curator.checkExists().forPath(testPath2));
|
Assert.assertArrayEquals("/test1 has data", billy, curator.getData().decompressed().forPath(testPath1));
|
||||||
|
Assert.assertNull("/somewhere/test2 still does not exist", curator.checkExists().forPath(testPath2));
|
||||||
|
|
||||||
announcer.announce(testPath2, billy);
|
announcer.announce(testPath2, billy);
|
||||||
|
|
||||||
Assert.assertArrayEquals("/test1 still has data", billy, curator.getData().decompressed().forPath(testPath1));
|
Assert.assertArrayEquals("/test1 still has data", billy, curator.getData().decompressed().forPath(testPath1));
|
||||||
Assert.assertArrayEquals("/somewhere/test2 has data", billy, curator.getData().decompressed().forPath(testPath2));
|
Assert.assertArrayEquals("/somewhere/test2 has data", billy, curator.getData().decompressed().forPath(testPath2));
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
curator.getCuratorListenable().addListener(
|
curator.getCuratorListenable().addListener(
|
||||||
new CuratorListener()
|
new CuratorListener()
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception
|
|
||||||
{
|
{
|
||||||
if (event.getType() == CuratorEventType.CREATE && event.getPath().equals(testPath1)) {
|
@Override
|
||||||
latch.countDown();
|
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception
|
||||||
|
{
|
||||||
|
if (event.getType() == CuratorEventType.CREATE && event.getPath().equals(testPath1)) {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
);
|
curator.inTransaction().delete().forPath(testPath1).and().commit();
|
||||||
curator.delete().forPath(testPath1);
|
Assert.assertTrue("Wait for /test1 to be created", timing.forWaiting().awaitLatch(latch));
|
||||||
Assert.assertTrue("Wait for /test1 to be created", timing.forWaiting().awaitLatch(latch));
|
|
||||||
|
|
||||||
Assert.assertArrayEquals("expect /test1 data is restored", billy, curator.getData().decompressed().forPath(testPath1));
|
Assert.assertArrayEquals(
|
||||||
Assert.assertArrayEquals("expect /somewhere/test2 is still there", billy, curator.getData().decompressed().forPath(testPath2));
|
"expect /test1 data is restored",
|
||||||
|
billy,
|
||||||
|
curator.getData().decompressed().forPath(testPath1)
|
||||||
|
);
|
||||||
|
Assert.assertArrayEquals(
|
||||||
|
"expect /somewhere/test2 is still there",
|
||||||
|
billy,
|
||||||
|
curator.getData().decompressed().forPath(testPath2)
|
||||||
|
);
|
||||||
|
|
||||||
announcer.unannounce(testPath1);
|
announcer.unannounce(testPath1);
|
||||||
Assert.assertNull("expect /test1 unannounced", curator.checkExists().forPath(testPath1));
|
Assert.assertNull("expect /test1 unannounced", curator.checkExists().forPath(testPath1));
|
||||||
Assert.assertArrayEquals("expect /somewhere/test2 is still still there", billy, curator.getData().decompressed().forPath(testPath2));
|
Assert.assertArrayEquals(
|
||||||
|
"expect /somewhere/test2 is still still there",
|
||||||
announcer.stop();
|
billy,
|
||||||
|
curator.getData().decompressed().forPath(testPath2)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
announcer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
Assert.assertNull("expect /test1 remains unannounced", curator.checkExists().forPath(testPath1));
|
Assert.assertNull("expect /test1 remains unannounced", curator.checkExists().forPath(testPath1));
|
||||||
Assert.assertNull("expect /somewhere/test2 unannounced", curator.checkExists().forPath(testPath2));
|
Assert.assertNull("expect /somewhere/test2 unannounced", curator.checkExists().forPath(testPath2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(timeout = 60_000L)
|
||||||
public void testSessionKilled() throws Exception
|
public void testSessionKilled() throws Exception
|
||||||
{
|
{
|
||||||
curator.start();
|
curator.start();
|
||||||
|
curator.blockUntilConnected();
|
||||||
Announcer announcer = new Announcer(curator, exec);
|
Announcer announcer = new Announcer(curator, exec);
|
||||||
try {
|
try {
|
||||||
curator.create().forPath("/somewhere");
|
curator.inTransaction().create().forPath("/somewhere").and().commit();
|
||||||
announcer.start();
|
announcer.start();
|
||||||
|
|
||||||
final byte[] billy = "billy".getBytes();
|
final byte[] billy = "billy".getBytes();
|
||||||
|
@ -172,14 +189,16 @@ public class AnnouncerTest extends CuratorTestBase
|
||||||
final String parent = ZKPaths.getPathAndNode(testPath).getPath();
|
final String parent = ZKPaths.getPathAndNode(testPath).getPath();
|
||||||
|
|
||||||
announcer.start();
|
announcer.start();
|
||||||
|
try {
|
||||||
|
Assert.assertNull(curator.checkExists().forPath(parent));
|
||||||
|
|
||||||
Assert.assertNull(curator.checkExists().forPath(parent));
|
announcer.announce(testPath, billy);
|
||||||
|
|
||||||
announcer.announce(testPath, billy);
|
Assert.assertNotNull(curator.checkExists().forPath(parent));
|
||||||
|
}
|
||||||
Assert.assertNotNull(curator.checkExists().forPath(parent));
|
finally {
|
||||||
|
announcer.stop();
|
||||||
announcer.stop();
|
}
|
||||||
|
|
||||||
Assert.assertNull(curator.checkExists().forPath(parent));
|
Assert.assertNull(curator.checkExists().forPath(parent));
|
||||||
}
|
}
|
||||||
|
@ -198,14 +217,16 @@ public class AnnouncerTest extends CuratorTestBase
|
||||||
final Stat initialStat = curator.checkExists().forPath(parent);
|
final Stat initialStat = curator.checkExists().forPath(parent);
|
||||||
|
|
||||||
announcer.start();
|
announcer.start();
|
||||||
|
try {
|
||||||
|
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
||||||
|
|
||||||
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
announcer.announce(testPath, billy);
|
||||||
|
|
||||||
announcer.announce(testPath, billy);
|
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
||||||
|
}
|
||||||
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
finally {
|
||||||
|
announcer.stop();
|
||||||
announcer.stop();
|
}
|
||||||
|
|
||||||
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
Assert.assertEquals(initialStat.getMzxid(), curator.checkExists().forPath(parent).getMzxid());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue