Try and make AnnouncerTest a bit more predictable

This commit is contained in:
Charles Allen 2015-10-01 11:52:04 -07:00
parent e5b3226b62
commit 7d635a2ce2
1 changed files with 60 additions and 39 deletions

View File

@ -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,6 +73,7 @@ public class AnnouncerTest extends CuratorTestBase
announcer.start(); announcer.start();
try {
Assert.assertArrayEquals("/test1 has data", billy, curator.getData().decompressed().forPath(testPath1)); Assert.assertArrayEquals("/test1 has data", billy, curator.getData().decompressed().forPath(testPath1));
Assert.assertNull("/somewhere/test2 still does not exist", curator.checkExists().forPath(testPath2)); Assert.assertNull("/somewhere/test2 still does not exist", curator.checkExists().forPath(testPath2));
@ -93,29 +95,44 @@ public class AnnouncerTest extends CuratorTestBase
} }
} }
); );
curator.delete().forPath(testPath1); curator.inTransaction().delete().forPath(testPath1).and().commit();
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",
billy,
curator.getData().decompressed().forPath(testPath2)
);
}
finally {
announcer.stop(); 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());
} }