Search in sources :

Example 1 with NoSuchTxnException

use of org.apache.hadoop.hive.metastore.api.NoSuchTxnException in project hive by apache.

the class TestTxnHandler method testHeartbeatNoTxn.

@Test
public void testHeartbeatNoTxn() throws Exception {
    // Test that when a transaction is aborted, the heartbeat fails
    HeartbeatRequest h = new HeartbeatRequest();
    h.setTxnid(939393L);
    try {
        txnHandler.heartbeat(h);
        fail("Told there was a txn, when there wasn't.");
    } catch (NoSuchTxnException e) {
    }
}
Also used : NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) HeartbeatRequest(org.apache.hadoop.hive.metastore.api.HeartbeatRequest) Test(org.junit.Test)

Example 2 with NoSuchTxnException

use of org.apache.hadoop.hive.metastore.api.NoSuchTxnException in project hive by apache.

the class TestTxnHandler method testAbortTxn.

@Test
public void testAbortTxn() throws Exception {
    OpenTxnsResponse openedTxns = txnHandler.openTxns(new OpenTxnRequest(3, "me", "localhost"));
    List<Long> txnList = openedTxns.getTxn_ids();
    long first = txnList.get(0);
    assertEquals(1L, first);
    long second = txnList.get(1);
    assertEquals(2L, second);
    txnHandler.abortTxn(new AbortTxnRequest(1));
    List<String> parts = new ArrayList<String>();
    parts.add("p=1");
    AddDynamicPartitions adp = new AddDynamicPartitions(3, "default", "T", parts);
    adp.setOperationType(DataOperationType.INSERT);
    txnHandler.addDynamicPartitions(adp);
    GetOpenTxnsInfoResponse txnsInfo = txnHandler.getOpenTxnsInfo();
    assertEquals(3, txnsInfo.getTxn_high_water_mark());
    assertEquals(3, txnsInfo.getOpen_txns().size());
    assertEquals(1L, txnsInfo.getOpen_txns().get(0).getId());
    assertEquals(TxnState.ABORTED, txnsInfo.getOpen_txns().get(0).getState());
    assertEquals(2L, txnsInfo.getOpen_txns().get(1).getId());
    assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(1).getState());
    assertEquals(3, txnsInfo.getOpen_txns().get(2).getId());
    assertEquals(TxnState.OPEN, txnsInfo.getOpen_txns().get(2).getState());
    GetOpenTxnsResponse txns = txnHandler.getOpenTxns();
    assertEquals(3, txns.getTxn_high_water_mark());
    assertEquals(3, txns.getOpen_txns().size());
    boolean[] saw = new boolean[4];
    for (int i = 0; i < saw.length; i++) saw[i] = false;
    for (Long tid : txns.getOpen_txns()) {
        saw[tid.intValue()] = true;
    }
    for (int i = 1; i < saw.length; i++) assertTrue(saw[i]);
    txnHandler.commitTxn(new CommitTxnRequest(2));
    //this succeeds as abortTxn is idempotent
    txnHandler.abortTxn(new AbortTxnRequest(1));
    boolean gotException = false;
    try {
        txnHandler.abortTxn(new AbortTxnRequest(2));
    } catch (NoSuchTxnException ex) {
        gotException = true;
        //if this wasn't an empty txn, we'd get a better msg
        Assert.assertEquals("No such transaction " + JavaUtils.txnIdToString(2), ex.getMessage());
    }
    Assert.assertTrue(gotException);
    gotException = false;
    txnHandler.commitTxn(new CommitTxnRequest(3));
    try {
        txnHandler.abortTxn(new AbortTxnRequest(3));
    } catch (NoSuchTxnException ex) {
        gotException = true;
        //txn 3 is not empty txn, so we get a better msg
        Assert.assertEquals("Transaction " + JavaUtils.txnIdToString(3) + " is already committed.", ex.getMessage());
    }
    Assert.assertTrue(gotException);
    gotException = false;
    try {
        txnHandler.abortTxn(new AbortTxnRequest(4));
    } catch (NoSuchTxnException ex) {
        gotException = true;
        Assert.assertEquals("No such transaction " + JavaUtils.txnIdToString(4), ex.getMessage());
    }
    Assert.assertTrue(gotException);
}
Also used : CommitTxnRequest(org.apache.hadoop.hive.metastore.api.CommitTxnRequest) ArrayList(java.util.ArrayList) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) AddDynamicPartitions(org.apache.hadoop.hive.metastore.api.AddDynamicPartitions) NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) GetOpenTxnsResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse) OpenTxnRequest(org.apache.hadoop.hive.metastore.api.OpenTxnRequest) OpenTxnsResponse(org.apache.hadoop.hive.metastore.api.OpenTxnsResponse) GetOpenTxnsResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse) GetOpenTxnsInfoResponse(org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse) Test(org.junit.Test)

Example 3 with NoSuchTxnException

use of org.apache.hadoop.hive.metastore.api.NoSuchTxnException in project hive by apache.

the class TestTxnHandler method testAbortInvalidTxn.

@Test
public void testAbortInvalidTxn() throws Exception {
    boolean caught = false;
    try {
        txnHandler.abortTxn(new AbortTxnRequest(195L));
    } catch (NoSuchTxnException e) {
        caught = true;
    }
    assertTrue(caught);
}
Also used : NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) AbortTxnRequest(org.apache.hadoop.hive.metastore.api.AbortTxnRequest) Test(org.junit.Test)

Example 4 with NoSuchTxnException

use of org.apache.hadoop.hive.metastore.api.NoSuchTxnException in project hive by apache.

the class TestHeartbeatTimerTask method testRunHeartbeatFailsNoSuchTxnException.

@Test
public void testRunHeartbeatFailsNoSuchTxnException() throws Exception {
    NoSuchTxnException exception = new NoSuchTxnException();
    doThrow(exception).when(mockMetaStoreClient).heartbeat(TRANSACTION_ID, LOCK_ID);
    task.run();
    verify(mockListener).lockFailed(LOCK_ID, TRANSACTION_ID, Arrays.asList("DB.TABLE"), exception);
}
Also used : NoSuchTxnException(org.apache.hadoop.hive.metastore.api.NoSuchTxnException) Test(org.junit.Test)

Aggregations

NoSuchTxnException (org.apache.hadoop.hive.metastore.api.NoSuchTxnException)4 Test (org.junit.Test)4 AbortTxnRequest (org.apache.hadoop.hive.metastore.api.AbortTxnRequest)2 ArrayList (java.util.ArrayList)1 AddDynamicPartitions (org.apache.hadoop.hive.metastore.api.AddDynamicPartitions)1 CommitTxnRequest (org.apache.hadoop.hive.metastore.api.CommitTxnRequest)1 GetOpenTxnsInfoResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsInfoResponse)1 GetOpenTxnsResponse (org.apache.hadoop.hive.metastore.api.GetOpenTxnsResponse)1 HeartbeatRequest (org.apache.hadoop.hive.metastore.api.HeartbeatRequest)1 OpenTxnRequest (org.apache.hadoop.hive.metastore.api.OpenTxnRequest)1 OpenTxnsResponse (org.apache.hadoop.hive.metastore.api.OpenTxnsResponse)1