Search in sources :

Example 16 with TransactionSystemClient

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

the class TransactionHttpHandlerTest method testTruncateInvalidTx.

@Test
public void testTruncateInvalidTx() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Remove tx1 and tx3 from invalid list
    HttpResponse response = doPost("/v3/transactions/invalid/remove/ids", GSON.toJson(ImmutableMap.of("ids", ImmutableSet.of(tx1.getWritePointer(), tx3.getWritePointer()))));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(1, txClient.getInvalidSize());
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 17 with TransactionSystemClient

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

the class TransactionHttpHandlerTest method testTruncateInvalidTxBefore.

@Test
public void testTruncateInvalidTxBefore() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    // Sleep so that transaction ids get generated a millisecond apart for assertion
    // TEPHRA-63 should eliminate the need to sleep
    TimeUnit.MILLISECONDS.sleep(1);
    long beforeTx3 = System.currentTimeMillis();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Remove all transactions in invalid list beforeTx3
    HttpResponse response = doPost("/v3/transactions/invalid/remove/until", GSON.toJson(ImmutableMap.of("time", beforeTx3)));
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Assert.assertEquals(1, txClient.getInvalidSize());
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 18 with TransactionSystemClient

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

the class TransactionHttpHandlerTest method testGetInvalidSize.

@Test
public void testGetInvalidSize() throws Exception {
    TransactionSystemClient txClient = getTxClient();
    // Reset state, and assert no invalid transactions are present
    txClient.resetState();
    Assert.assertEquals(0, txClient.getInvalidSize());
    // Start few transactions and invalidate them
    Transaction tx1 = txClient.startShort();
    Transaction tx2 = txClient.startLong();
    Transaction tx3 = txClient.startLong();
    Assert.assertTrue(txClient.invalidate(tx1.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx2.getWritePointer()));
    Assert.assertTrue(txClient.invalidate(tx3.getWritePointer()));
    Assert.assertEquals(3, txClient.getInvalidSize());
    // Assert through REST API
    HttpResponse response = doGet("/v3/transactions/invalid/size");
    Assert.assertEquals(200, response.getStatusLine().getStatusCode());
    Map<String, Integer> resultMap = GSON.fromJson(EntityUtils.toString(response.getEntity()), STRING_INT_TYPE);
    Assert.assertNotNull(resultMap);
    Assert.assertEquals(3, (int) resultMap.get("size"));
}
Also used : TransactionSystemClient(org.apache.tephra.TransactionSystemClient) Transaction(org.apache.tephra.Transaction) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Aggregations

TransactionSystemClient (org.apache.tephra.TransactionSystemClient)18 Test (org.junit.Test)12 Transaction (org.apache.tephra.Transaction)10 TransactionAware (org.apache.tephra.TransactionAware)6 CConfiguration (co.cask.cdap.common.conf.CConfiguration)5 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)5 HttpResponse (org.apache.http.HttpResponse)5 DynamicTransactionExecutorFactory (co.cask.cdap.data.runtime.DynamicTransactionExecutorFactory)4 DiscoveryServiceClient (org.apache.twill.discovery.DiscoveryServiceClient)4 NamespaceAdmin (co.cask.cdap.common.namespace.NamespaceAdmin)3 TransactionExecutorFactory (co.cask.cdap.data2.transaction.TransactionExecutorFactory)3 BasicArguments (co.cask.cdap.internal.app.runtime.BasicArguments)3 TransactionExecutor (org.apache.tephra.TransactionExecutor)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)2 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)2 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)2 ProgramDescriptor (co.cask.cdap.app.program.ProgramDescriptor)2 ProgramController (co.cask.cdap.app.runtime.ProgramController)2 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)2 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2