use of co.cask.cdap.data2.dataset2.DynamicDatasetCache in project cdap by caskdata.
the class MultiConsumerTest method testMulti.
@Test
public void testMulti() throws Exception {
// TODO: Fix this test case to really test with numGroups settings.
final ApplicationWithPrograms app = AppFabricTestHelper.deployApplicationWithManager(MultiApp.class, TEMP_FOLDER_SUPPLIER);
List<ProgramController> controllers = Lists.newArrayList();
for (ProgramDescriptor programDescriptor : app.getPrograms()) {
controllers.add(AppFabricTestHelper.submit(app, programDescriptor.getSpecification().getClassName(), new BasicArguments(), TEMP_FOLDER_SUPPLIER));
}
DatasetFramework datasetFramework = AppFabricTestHelper.getInjector().getInstance(DatasetFramework.class);
DynamicDatasetCache datasetCache = new SingleThreadDatasetCache(new SystemDatasetInstantiator(datasetFramework, getClass().getClassLoader(), null), AppFabricTestHelper.getInjector().getInstance(TransactionSystemClient.class), NamespaceId.DEFAULT, DatasetDefinition.NO_ARGUMENTS, null, null);
final KeyValueTable accumulated = datasetCache.getDataset("accumulated");
TransactionExecutorFactory txExecutorFactory = AppFabricTestHelper.getInjector().getInstance(TransactionExecutorFactory.class);
// Try to get accumulated result and verify it. Expect result appear in max of 60 seconds.
int trial = 0;
while (trial < 60) {
try {
Transactions.createTransactionExecutor(txExecutorFactory, accumulated).execute(new TransactionExecutor.Subroutine() {
@Override
public void apply() throws Exception {
byte[] value = accumulated.read(MultiApp.KEY);
// Sum(1..100) * 3
Assert.assertEquals(((1 + 99) * 99 / 2) * 3, Longs.fromByteArray(value));
}
});
break;
} catch (TransactionFailureException e) {
// No-op
trial++;
TimeUnit.SECONDS.sleep(1);
}
}
Assert.assertTrue(trial < 60);
for (ProgramController controller : controllers) {
controller.stop().get();
}
}
Aggregations