@Test public void testTrackingWithZkUpdate() throws Exception { TimestampTracker tracker = new TimestampTracker(env, new TransactorID(env), 5); final long ts1 = tracker.allocateTimestamp().getTxTimestamp(); Thread.sleep(15); Assert.assertNotNull(ts1); Assert.assertTrue(zkNodeExists(tracker)); Assert.assertNotNull(zkNodeValue(tracker)); Assert.assertEquals(tracker.getZookeeperTimestamp(), zkNodeValue(tracker)); Assert.assertEquals(ts1, tracker.getOldestActiveTimestamp()); final long ts2 = tracker.allocateTimestamp().getTxTimestamp(); Assert.assertEquals(ts1, tracker.getOldestActiveTimestamp()); Thread.sleep(15); tracker.removeTimestamp(ts1); Thread.sleep(15); Assert.assertEquals(ts2, tracker.getOldestActiveTimestamp()); Assert.assertEquals(ts2, zkNodeValue(tracker)); tracker.removeTimestamp(ts2); Thread.sleep(15); Assert.assertTrue(tracker.isEmpty()); Assert.assertFalse(zkNodeExists(tracker)); tracker.close(); }
@Test public void testTimestampUtilGetOldestTs() throws Exception { Assert.assertEquals(0, getOldestTs()); TimestampTracker tr1 = new TimestampTracker(env, new TransactorID(env), 5); final long ts1 = tr1.allocateTimestamp().getTxTimestamp(); Thread.sleep(15); Assert.assertEquals(tr1.getZookeeperTimestamp(), getOldestTs()); TimestampTracker tr2 = new TimestampTracker(env, new TransactorID(env), 5); final long ts2 = tr2.allocateTimestamp().getTxTimestamp(); TimestampTracker tr3 = new TimestampTracker(env, new TransactorID(env), 5); final long ts3 = tr3.allocateTimestamp().getTxTimestamp(); Thread.sleep(15); Assert.assertEquals(ts1, getOldestTs()); tr1.removeTimestamp(ts1); Thread.sleep(15); Assert.assertEquals(ts2, getOldestTs()); tr2.removeTimestamp(ts2); Thread.sleep(15); Assert.assertEquals(ts3, getOldestTs()); tr3.removeTimestamp(ts3); tr1.close(); tr2.close(); tr3.close(); }
@Test public void testTrackingWithNoUpdate() throws Exception { TimestampTracker tracker = new TimestampTracker(env, new TransactorID(env)); Assert.assertTrue(tracker.isEmpty()); Assert.assertFalse(zkNodeExists(tracker)); final long ts1 = tracker.allocateTimestamp().getTxTimestamp(); Assert.assertFalse(tracker.isEmpty()); Assert.assertTrue(zkNodeExists(tracker)); Assert.assertTrue(ts1 > zkNodeValue(tracker)); Assert.assertEquals(tracker.getZookeeperTimestamp(), zkNodeValue(tracker)); Assert.assertEquals(ts1, tracker.getOldestActiveTimestamp()); final long ts2 = tracker.allocateTimestamp().getTxTimestamp(); Assert.assertEquals(ts1, tracker.getOldestActiveTimestamp()); tracker.removeTimestamp(ts1); Assert.assertFalse(tracker.isEmpty()); Assert.assertEquals(ts2, tracker.getOldestActiveTimestamp()); Assert.assertFalse(tracker.isEmpty()); Assert.assertTrue(ts1 > zkNodeValue(tracker)); Assert.assertEquals(tracker.getZookeeperTimestamp(), zkNodeValue(tracker)); tracker.removeTimestamp(ts2); Assert.assertTrue(tracker.isEmpty()); Assert.assertTrue(zkNodeExists(tracker)); tracker.close(); }