Search in sources :

Example 1 with AppMetadataStore

use of co.cask.cdap.internal.app.store.AppMetadataStore in project cdap by caskdata.

the class ProgramNotificationSubscriberServiceTest method testAppSpecNotRequiredToWriteState.

@Test
public void testAppSpecNotRequiredToWriteState() throws Exception {
    Injector injector = AppFabricTestHelper.getInjector();
    CConfiguration cConf = injector.getInstance(CConfiguration.class);
    ProgramNotificationSubscriberService programNotificationSubscriberService = injector.getInstance(ProgramNotificationSubscriberService.class);
    programNotificationSubscriberService.startAndWait();
    DatasetFramework datasetFramework = injector.getInstance(DatasetFramework.class);
    TransactionExecutorFactory txExecutorFactory = injector.getInstance(TransactionExecutorFactory.class);
    DatasetId storeTable = NamespaceId.SYSTEM.dataset(Constants.AppMetaStore.TABLE);
    Table table = DatasetsUtil.getOrCreateDataset(datasetFramework, storeTable, Table.class.getName(), DatasetProperties.EMPTY, Collections.<String, String>emptyMap());
    final AppMetadataStore metadataStoreDataset = new AppMetadataStore(table, cConf, new AtomicBoolean(false));
    final TransactionExecutor txnl = txExecutorFactory.createExecutor(Collections.singleton((TransactionAware) metadataStoreDataset));
    ProgramStateWriter programStateWriter = injector.getInstance(ProgramStateWriter.class);
    ProgramId programId = NamespaceId.DEFAULT.app("someapp").program(ProgramType.SERVICE, "s");
    ProgramOptions programOptions = new SimpleProgramOptions(programId);
    final ProgramRunId runId = programId.run(RunIds.generate());
    programStateWriter.start(runId, programOptions, null);
    Tasks.waitFor(ProgramRunStatus.STARTING, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.running(runId, UUID.randomUUID().toString());
    Tasks.waitFor(ProgramRunStatus.RUNNING, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
    programStateWriter.killed(runId);
    Tasks.waitFor(ProgramRunStatus.KILLED, () -> txnl.execute(() -> {
        RunRecordMeta meta = metadataStoreDataset.getRun(runId);
        return meta == null ? null : meta.getStatus();
    }), 10, TimeUnit.SECONDS);
}
Also used : Table(co.cask.cdap.api.dataset.table.Table) AppMetadataStore(co.cask.cdap.internal.app.store.AppMetadataStore) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) TransactionExecutor(org.apache.tephra.TransactionExecutor) ProgramId(co.cask.cdap.proto.id.ProgramId) CConfiguration(co.cask.cdap.common.conf.CConfiguration) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramOptions(co.cask.cdap.app.runtime.ProgramOptions) TransactionExecutorFactory(co.cask.cdap.data2.transaction.TransactionExecutorFactory) DatasetId(co.cask.cdap.proto.id.DatasetId) DatasetFramework(co.cask.cdap.data2.dataset2.DatasetFramework) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProgramStateWriter(co.cask.cdap.app.runtime.ProgramStateWriter) Injector(com.google.inject.Injector) TransactionAware(org.apache.tephra.TransactionAware) SimpleProgramOptions(co.cask.cdap.internal.app.runtime.SimpleProgramOptions) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Test(org.junit.Test)

Aggregations

Table (co.cask.cdap.api.dataset.table.Table)1 ProgramOptions (co.cask.cdap.app.runtime.ProgramOptions)1 ProgramStateWriter (co.cask.cdap.app.runtime.ProgramStateWriter)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)1 TransactionExecutorFactory (co.cask.cdap.data2.transaction.TransactionExecutorFactory)1 SimpleProgramOptions (co.cask.cdap.internal.app.runtime.SimpleProgramOptions)1 AppMetadataStore (co.cask.cdap.internal.app.store.AppMetadataStore)1 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)1 DatasetId (co.cask.cdap.proto.id.DatasetId)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 ProgramRunId (co.cask.cdap.proto.id.ProgramRunId)1 Injector (com.google.inject.Injector)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 TransactionAware (org.apache.tephra.TransactionAware)1 TransactionExecutor (org.apache.tephra.TransactionExecutor)1 Test (org.junit.Test)1