Search in sources :

Example 31 with Get

use of co.cask.cdap.api.dataset.table.Get in project cdap by caskdata.

the class MapReduceProgramRunnerTest method testFailure.

// TODO: this tests failure in Map tasks. We also need to test: failure in Reduce task, kill of a job by user.
private void testFailure(boolean frequentFlushing) throws Exception {
    // We want to verify that when mapreduce job fails:
    // * things written in initialize() remains and visible to others
    // * things written in tasks not visible to others TODO AAA: do invalidate
    // * things written in onfinish() remains and visible to others
    // NOTE: the code of this test is similar to testTimeSeriesRecordsCount() test. We put some "bad data" intentionally
    //       here to be recognized by map tasks as a message to emulate failure
    final ApplicationWithPrograms app = deployApp(AppWithMapReduce.class);
    // we need to start a tx context and do a "get" on all datasets so that they are in datasetCache
    datasetCache.newTransactionContext();
    final TimeseriesTable table = datasetCache.getDataset("timeSeries");
    final KeyValueTable beforeSubmitTable = datasetCache.getDataset("beforeSubmit");
    final KeyValueTable onFinishTable = datasetCache.getDataset("onFinish");
    final Table counters = datasetCache.getDataset("counters");
    final Table countersFromContext = datasetCache.getDataset("countersFromContext");
    // 1) fill test data
    fillTestInputData(txExecutorFactory, table, true);
    // 2) run job
    final long start = System.currentTimeMillis();
    runProgram(app, AppWithMapReduce.AggregateTimeseriesByTag.class, frequentFlushing, false);
    final long stop = System.currentTimeMillis();
    // 3) verify results
    Transactions.createTransactionExecutor(txExecutorFactory, datasetCache.getTransactionAwares()).execute(new TransactionExecutor.Subroutine() {

        @Override
        public void apply() {
            // data should be rolled back todo: test that partially written is rolled back too
            Assert.assertFalse(table.read(AggregateMetricsByTag.BY_TAGS, start, stop).hasNext());
            // but written beforeSubmit and onFinish is available to others
            Assert.assertArrayEquals(Bytes.toBytes("beforeSubmit:done"), beforeSubmitTable.read(Bytes.toBytes("beforeSubmit")));
            Assert.assertArrayEquals(Bytes.toBytes("onFinish:done"), onFinishTable.read(Bytes.toBytes("onFinish")));
            Assert.assertEquals(0, counters.get(new Get("mapper")).getLong("records", 0));
            Assert.assertEquals(0, counters.get(new Get("reducer")).getLong("records", 0));
            Assert.assertEquals(0, countersFromContext.get(new Get("mapper")).getLong("records", 0));
            Assert.assertEquals(0, countersFromContext.get(new Get("reducer")).getLong("records", 0));
        }
    });
    datasetCache.dismissTransactionContext();
}
Also used : TimeseriesTable(co.cask.cdap.api.dataset.lib.TimeseriesTable) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Table(co.cask.cdap.api.dataset.table.Table) ApplicationWithPrograms(co.cask.cdap.internal.app.deploy.pipeline.ApplicationWithPrograms) KeyValueTable(co.cask.cdap.api.dataset.lib.KeyValueTable) Get(co.cask.cdap.api.dataset.table.Get) TransactionExecutor(org.apache.tephra.TransactionExecutor) TimeseriesTable(co.cask.cdap.api.dataset.lib.TimeseriesTable)

Aggregations

Get (co.cask.cdap.api.dataset.table.Get)31 Table (co.cask.cdap.api.dataset.table.Table)17 Row (co.cask.cdap.api.dataset.table.Row)16 Test (org.junit.Test)15 Put (co.cask.cdap.api.dataset.table.Put)13 TransactionAware (org.apache.tephra.TransactionAware)9 DatasetAdmin (co.cask.cdap.api.dataset.DatasetAdmin)8 Transaction (org.apache.tephra.Transaction)8 HBaseTable (co.cask.cdap.data2.dataset2.lib.table.hbase.HBaseTable)7 KeyValueTable (co.cask.cdap.api.dataset.lib.KeyValueTable)6 TransactionExecutor (org.apache.tephra.TransactionExecutor)6 NotFoundException (co.cask.cdap.common.NotFoundException)5 IOException (java.io.IOException)4 ReadOnly (co.cask.cdap.api.annotation.ReadOnly)3 DatasetProperties (co.cask.cdap.api.dataset.DatasetProperties)3 Delete (co.cask.cdap.api.dataset.table.Delete)3 Scanner (co.cask.cdap.api.dataset.table.Scanner)3 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)3 ApplicationManager (co.cask.cdap.test.ApplicationManager)3 FlowManager (co.cask.cdap.test.FlowManager)3