use of herddb.client.TableSpaceDumpReceiver in project herddb by diennea.
the class DownloadTableSpaceTest method downloadTablespaceTest.
@Test
public void downloadTablespaceTest() throws Exception {
ServerConfiguration serverconfig_1 = new ServerConfiguration(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_PORT, 7867);
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
try (Server server_1 = new Server(serverconfig_1)) {
server_1.start();
server_1.waitForStandaloneBoot();
Table table = Table.builder().name("t1").column("c", ColumnTypes.INTEGER).primaryKey("c").build();
server_1.getManager().executeStatement(new CreateTableStatement(table), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
for (int i = 0; i < 1000; i++) {
server_1.getManager().executeUpdate(new InsertStatement(TableSpace.DEFAULT, "t1", RecordSerializer.makeRecord(table, "c", i)), StatementEvaluationContext.DEFAULT_EVALUATION_CONTEXT(), TransactionContext.NO_TRANSACTION);
}
List<Map<String, Object>> logical_data = new ArrayList<>();
AtomicBoolean start = new AtomicBoolean();
try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
HDBConnection con = client.openConnection()) {
client.setClientSideMetadataProvider(new ZookeeperClientSideMetadataProvider(testEnv.getAddress(), testEnv.getTimeout(), testEnv.getPath()));
CountDownLatch count = new CountDownLatch(1);
con.dumpTableSpace(TableSpace.DEFAULT, new TableSpaceDumpReceiver() {
Table table;
@Override
public void start(LogSequenceNumber logSequenceNumber) throws DataStorageManagerException {
System.out.println("start at " + logSequenceNumber);
start.set(true);
}
@Override
public void finish(LogSequenceNumber logSequenceNumber) {
System.out.println("finish!");
count.countDown();
}
@Override
public void endTable() {
System.out.println("endTable");
table = null;
}
@Override
public void receiveTableDataChunk(List<Record> records) {
// System.out.println("receiveTableDataChunk " + records);
for (Record r : records) {
Map<String, Object> bean = r.toBean(table);
// System.out.println("received:" + bean);
logical_data.add(bean);
}
}
@Override
public void beginTable(DumpedTableMetadata table, Map<String, Object> stats) {
System.out.println("beginTable " + table);
this.table = table.table;
}
}, 89, false);
assertTrue(count.await(20, TimeUnit.SECONDS));
assertEquals(1000, logical_data.size());
assertTrue(start.get());
}
}
}
Aggregations