/** * Test setting and reading the most recent propagated timestamp. */ @Test(timeout = 100000) public void testLastPropagatedTimestamps() throws Exception { // Scan a table to ensure a timestamp is propagated. KuduTable table = client.createTable(TABLE_NAME, basicSchema, getBasicCreateTableOptions()); client.newScannerBuilder(table).build().nextRows().getNumRows(); assertTrue(client.hasLastPropagatedTimestamp()); assertTrue(client.hasLastPropagatedTimestamp()); assertTrue(asyncClient.hasLastPropagatedTimestamp()); long initial_ts = client.getLastPropagatedTimestamp(); // Check that the initial timestamp is consistent with the asynchronous client. assertEquals(initial_ts, client.getLastPropagatedTimestamp()); assertEquals(initial_ts, asyncClient.getLastPropagatedTimestamp()); // Attempt to change the timestamp to a lower value. This should not change // the internal timestamp, as it must be monotonically increasing. client.updateLastPropagatedTimestamp(initial_ts - 1); assertEquals(initial_ts, client.getLastPropagatedTimestamp()); assertEquals(initial_ts, asyncClient.getLastPropagatedTimestamp()); // Use the synchronous client to update the last propagated timestamp and // check with both clients that the timestamp was updated. client.updateLastPropagatedTimestamp(initial_ts + 1); assertEquals(initial_ts + 1, client.getLastPropagatedTimestamp()); assertEquals(initial_ts + 1, asyncClient.getLastPropagatedTimestamp()); }
assertEquals(KuduClient.NO_TIMESTAMP, client.getLastPropagatedTimestamp()); KuduScanner syncScanner = new KuduScanner(scanner); assertEquals(KuduClient.NO_TIMESTAMP, client.getLastPropagatedTimestamp()); long syncTsRef = client.getLastPropagatedTimestamp(); assertEquals(asyncTsRef, syncTsRef); assertNotEquals(AsyncKuduClient.NO_TIMESTAMP, asyncTsRef); rowCount += syncScanner.nextRows().getNumRows(); final long asyncTs = asyncClient.getLastPropagatedTimestamp(); final long syncTs = client.getLastPropagatedTimestamp();
OperationResponse response = session.apply(insert); assertTrue(client.hasLastPropagatedTimestamp()); assertEquals(client.getLastPropagatedTimestamp(), response.getWriteTimestampRaw()); clockValues = HTTimestampToPhysicalAndLogical(client.getLastPropagatedTimestamp()); LOG.debug("Clock value after write[" + i + "]: " + new Date(clockValues[0] / 1000).toString() + " Logical value: " + clockValues[1]); assertEquals(client.getLastPropagatedTimestamp(), response.getWriteTimestampRaw()); clockValues = HTTimestampToPhysicalAndLogical(client.getLastPropagatedTimestamp()); LOG.debug("Clock value after write[" + i + "]: " + new Date(clockValues[0] / 1000).toString() + " Logical value: " + clockValues[1]); client.updateLastPropagatedTimestamp(client.getLastPropagatedTimestamp() + 1); snapTime = physicalAndLogicalToHTTimestamp(previousPhysicalValue, previousLogicalValue + 1); assertEquals(6, scanAtSnapshot(snapTime));
@Test(timeout = 100000) public void testScanTokenPropagatesTimestamp() throws Exception { // Initially, the client does not have the timestamp set. assertEquals(AsyncKuduClient.NO_TIMESTAMP, asyncClient.getLastPropagatedTimestamp()); assertEquals(KuduClient.NO_TIMESTAMP, client.getLastPropagatedTimestamp()); AsyncKuduScanner scanner = asyncClient.newScannerBuilder(table).build(); KuduScanner syncScanner = new KuduScanner(scanner); // Let the client receive the propagated timestamp in the scanner response. syncScanner.nextRows().getNumRows(); final long tsPrev = asyncClient.getLastPropagatedTimestamp(); final long tsPropagated = tsPrev + 1000000; ScanTokenPB.Builder pbBuilder = ScanTokenPB.newBuilder(); pbBuilder.setTableName(table.getName()); pbBuilder.setPropagatedTimestamp(tsPropagated); Client.ScanTokenPB scanTokenPB = pbBuilder.build(); final byte[] serializedToken = KuduScanToken.serialize(scanTokenPB); // Deserialize scan tokens and make sure the client's last propagated // timestamp is updated accordingly. assertEquals(tsPrev, asyncClient.getLastPropagatedTimestamp()); KuduScanToken.deserializeIntoScanner(serializedToken, client); assertEquals(tsPropagated, asyncClient.getLastPropagatedTimestamp()); }