Search in sources :

Example 16 with HBaseException

use of org.hbase.async.HBaseException in project opentsdb by OpenTSDB.

the class TestUniqueId method getOrCreateIdUnableToIncrementMaxId.

// Test the creation of an ID when unable to increment MAXID
@Test
public void getOrCreateIdUnableToIncrementMaxId() throws Exception {
    PowerMockito.mockStatic(Thread.class);
    uid = new UniqueId(client, table, METRIC, 3);
    // null  =>  ID doesn't exist.
    when(client.get(anyGet())).thenReturn(Deferred.<ArrayList<KeyValue>>fromResult(null));
    // Watch this! ______,^   I'm writing C++ in Java!
    HBaseException hbe = fakeHBaseException();
    when(client.atomicIncrement(incrementForRow(MAXID))).thenThrow(hbe);
    PowerMockito.doNothing().when(Thread.class);
    Thread.sleep(anyInt());
    try {
        uid.getOrCreateId("foo");
        fail("HBaseException should have been thrown!");
    } catch (HBaseException e) {
        assertSame(hbe, e);
    }
}
Also used : KeyValue(org.hbase.async.KeyValue) HBaseException(org.hbase.async.HBaseException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HBaseException (org.hbase.async.HBaseException)16 ArrayList (java.util.ArrayList)9 KeyValue (org.hbase.async.KeyValue)9 Callback (com.stumbleupon.async.Callback)5 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)4 Map (java.util.Map)4 PutRequest (org.hbase.async.PutRequest)4 Scanner (org.hbase.async.Scanner)4 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)3 HashMap (java.util.HashMap)3 DeleteRequest (org.hbase.async.DeleteRequest)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)2 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)2 UniqueId (net.opentsdb.uid.UniqueId)2 JSONException (net.opentsdb.utils.JSONException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1