Search in sources :

Example 21 with TransactionManager

use of org.apache.tephra.TransactionManager in project cdap by caskdata.

the class SparkTransactionHandlerTest method init.

@BeforeClass
public static void init() throws UnknownHostException {
    txManager = new TransactionManager(new Configuration());
    txManager.startAndWait();
    txClient = new InMemoryTxSystemClient(txManager);
    sparkTxHandler = new SparkTransactionHandler(txClient);
    httpService = new SparkDriverHttpService("test", InetAddress.getLoopbackAddress().getCanonicalHostName(), sparkTxHandler);
    httpService.startAndWait();
    sparkTxClient = new SparkTransactionClient(httpService.getBaseURI());
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) TransactionManager(org.apache.tephra.TransactionManager) InMemoryTxSystemClient(org.apache.tephra.inmemory.InMemoryTxSystemClient) BeforeClass(org.junit.BeforeClass)

Example 22 with TransactionManager

use of org.apache.tephra.TransactionManager in project cdap by caskdata.

the class SparkTransactionHandlerTest method testFailureTransaction.

/**
   * Tests the case where starting of transaction failed.
   */
@Test
public void testFailureTransaction() throws Exception {
    TransactionManager txManager = new TransactionManager(new Configuration()) {

        @Override
        public Transaction startLong() {
            throw new IllegalStateException("Cannot start long transaction");
        }
    };
    txManager.startAndWait();
    try {
        SparkTransactionHandler txHandler = new SparkTransactionHandler(new InMemoryTxSystemClient(txManager));
        SparkDriverHttpService httpService = new SparkDriverHttpService("test", InetAddress.getLoopbackAddress().getCanonicalHostName(), txHandler);
        httpService.startAndWait();
        try {
            // Start a job
            txHandler.jobStarted(1, ImmutableSet.of(2));
            // Make a call to the stage transaction endpoint, it should throw TransactionFailureException
            try {
                new SparkTransactionClient(httpService.getBaseURI()).getTransaction(2, 1, TimeUnit.SECONDS);
                Assert.fail("Should failed to get transaction");
            } catch (TransactionFailureException e) {
            // expected
            }
            // End the job
            txHandler.jobEnded(1, false);
        } finally {
            httpService.stopAndWait();
        }
    } finally {
        txManager.stopAndWait();
    }
}
Also used : TransactionFailureException(org.apache.tephra.TransactionFailureException) Configuration(org.apache.hadoop.conf.Configuration) TransactionManager(org.apache.tephra.TransactionManager) InMemoryTxSystemClient(org.apache.tephra.inmemory.InMemoryTxSystemClient) Test(org.junit.Test)

Aggregations

TransactionManager (org.apache.tephra.TransactionManager)22 Configuration (org.apache.hadoop.conf.Configuration)13 Injector (com.google.inject.Injector)12 ConfigModule (co.cask.cdap.common.guice.ConfigModule)11 AuthorizationEnforcementModule (co.cask.cdap.security.authorization.AuthorizationEnforcementModule)11 AuthorizationTestModule (co.cask.cdap.security.authorization.AuthorizationTestModule)11 BeforeClass (org.junit.BeforeClass)11 DiscoveryRuntimeModule (co.cask.cdap.common.guice.DiscoveryRuntimeModule)10 AuthenticationContextModules (co.cask.cdap.security.auth.context.AuthenticationContextModules)10 AbstractModule (com.google.inject.AbstractModule)10 CConfiguration (co.cask.cdap.common.conf.CConfiguration)9 DataSetsModules (co.cask.cdap.data.runtime.DataSetsModules)9 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)9 NamespaceClientRuntimeModule (co.cask.cdap.common.namespace.guice.NamespaceClientRuntimeModule)8 NonCustomLocationUnitTestModule (co.cask.cdap.common.guice.NonCustomLocationUnitTestModule)7 DataFabricModules (co.cask.cdap.data.runtime.DataFabricModules)6 ExploreClientModule (co.cask.cdap.explore.guice.ExploreClientModule)6 InMemoryTxSystemClient (org.apache.tephra.inmemory.InMemoryTxSystemClient)6 DataSetServiceModules (co.cask.cdap.data.runtime.DataSetServiceModules)5 UnsupportedUGIProvider (co.cask.cdap.security.impersonation.UnsupportedUGIProvider)5