use of io.cdap.cdap.test.DataSetManager in project cdap by caskdata.
the class SparkTest method testTransaction.
@Test
public void testTransaction() throws Exception {
ApplicationManager applicationManager = deploy(TestSparkApp.class);
// Write some data to a local file
File inputFile = TEMP_FOLDER.newFile();
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(inputFile.toPath(), StandardCharsets.UTF_8))) {
writer.println("red fox");
writer.println("brown fox");
writer.println("grey fox");
writer.println("brown bear");
writer.println("black bear");
}
// Run the spark program
SparkManager sparkManager = applicationManager.getSparkManager(TransactionSpark.class.getSimpleName());
sparkManager.start(ImmutableMap.of("input.file", inputFile.getAbsolutePath(), "keyvalue.table", "KeyValueTable", "result.all.dataset", "SparkResult", "result.threshold", "2", "result.threshold.dataset", "SparkThresholdResult"));
// Verify result from dataset before the Spark program terminates
final DataSetManager<KeyValueTable> resultManager = getDataset("SparkThresholdResult");
final KeyValueTable resultTable = resultManager.get();
// Expect the threshold result dataset, with threshold >=2, contains [brown, fox, bear]
Tasks.waitFor(ImmutableSet.of("brown", "fox", "bear"), () -> {
// This is to start a new TX
resultManager.flush();
LOG.info("Reading from threshold result");
try (CloseableIterator<KeyValue<byte[], byte[]>> itor = resultTable.scan(null, null)) {
return ImmutableSet.copyOf(Iterators.transform(itor, input -> {
String word = Bytes.toString(input.getKey());
LOG.info("{}, {}", word, Bytes.toInt(input.getValue()));
return word;
}));
}
}, 3, TimeUnit.MINUTES, 1, TimeUnit.SECONDS);
sparkManager.stop();
sparkManager.waitForRun(ProgramRunStatus.KILLED, 60, TimeUnit.SECONDS);
}
use of io.cdap.cdap.test.DataSetManager in project cdap by caskdata.
the class TestFrameworkTestRun method testAppWithWorker.
@Category(SlowTests.class)
@Test
public void testAppWithWorker() throws Exception {
ApplicationManager applicationManager = deployApplication(testSpace, AppWithWorker.class);
LOG.info("Deployed.");
WorkerManager manager = applicationManager.getWorkerManager(AppWithWorker.WORKER).start();
// Wait for initialize and run states
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET));
KeyValueTable table = dataSetManager.get();
return AppWithWorker.INITIALIZE.equals(Bytes.toString(table.read(AppWithWorker.INITIALIZE))) && AppWithWorker.RUN.equals(Bytes.toString(table.read(AppWithWorker.RUN)));
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
manager.stop();
applicationManager.stopAll();
// Wait for stop state
Tasks.waitFor(true, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
DataSetManager<KeyValueTable> dataSetManager = getDataset(testSpace.dataset(AppWithWorker.DATASET));
KeyValueTable table = dataSetManager.get();
return AppWithWorker.STOP.equals(Bytes.toString(table.read(AppWithWorker.STOP)));
}
}, 10, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
}
Aggregations