Search in sources :

Example 6 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestUniqueId method getOrCreateIdPutsReverseMappingFirst.

// Test that the reverse mapping is created before the forward one.
@Test
public void getOrCreateIdPutsReverseMappingFirst() {
    uid = new UniqueId(client, table, METRIC, 3);
    final Config config = mock(Config.class);
    when(config.enable_realtime_uid()).thenReturn(false);
    final TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    uid.setTSDB(tsdb);
    // null  =>  ID doesn't exist.
    when(client.get(anyGet())).thenReturn(Deferred.<ArrayList<KeyValue>>fromResult(null));
    // Watch this! ______,^   I'm writing C++ in Java!
    when(client.atomicIncrement(incrementForRow(MAXID))).thenReturn(Deferred.fromResult(6L));
    when(client.compareAndSet(anyPut(), emptyArray())).thenReturn(Deferred.fromResult(true)).thenReturn(Deferred.fromResult(true));
    final byte[] id = { 0, 0, 6 };
    final byte[] row = { 'f', 'o', 'o' };
    assertArrayEquals(id, uid.getOrCreateId("foo"));
    final InOrder order = inOrder(client);
    // Initial Get.
    order.verify(client).get(anyGet());
    order.verify(client).atomicIncrement(incrementForRow(MAXID));
    order.verify(client).compareAndSet(putForRow(id), emptyArray());
    order.verify(client).compareAndSet(putForRow(row), emptyArray());
}
Also used : KeyValue(org.hbase.async.KeyValue) InOrder(org.mockito.InOrder) Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestUniqueId method getOrCreateIdAsyncAssignFilterBlocked.

@Test(expected = FailedToAssignUniqueIdException.class)
public void getOrCreateIdAsyncAssignFilterBlocked() throws Exception {
    uid = new UniqueId(client, table, METRIC, 3);
    final Config config = mock(Config.class);
    when(config.enable_realtime_uid()).thenReturn(false);
    final TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    uid.setTSDB(tsdb);
    final UniqueIdFilterPlugin filter = mock(UniqueIdFilterPlugin.class);
    when(filter.fillterUIDAssignments()).thenReturn(true);
    when(filter.allowUIDAssignment(any(UniqueIdType.class), anyString(), anyString(), anyMapOf(String.class, String.class))).thenReturn(Deferred.fromResult(false));
    when(tsdb.getUidFilter()).thenReturn(filter);
    // null  =>  ID doesn't exist.
    when(client.get(anyGet())).thenReturn(Deferred.<ArrayList<KeyValue>>fromResult(null));
    when(client.atomicIncrement(incrementForRow(MAXID))).thenReturn(Deferred.fromResult(5L));
    when(client.compareAndSet(anyPut(), emptyArray())).thenReturn(Deferred.fromResult(true)).thenReturn(Deferred.fromResult(true));
    uid.getOrCreateIdAsync("foo").join();
}
Also used : KeyValue(org.hbase.async.KeyValue) Config(net.opentsdb.utils.Config) UniqueIdType(net.opentsdb.uid.UniqueId.UniqueIdType) TSDB(net.opentsdb.core.TSDB) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestUniqueId method getOrCreateIdWithICVFailure.

// ICV throws an exception, we can't get an ID.
@Test
public void getOrCreateIdWithICVFailure() {
    uid = new UniqueId(client, table, METRIC, 3);
    final Config config = mock(Config.class);
    when(config.enable_realtime_uid()).thenReturn(false);
    final TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    uid.setTSDB(tsdb);
    // null  =>  ID doesn't exist.
    when(client.get(anyGet())).thenReturn(Deferred.<ArrayList<KeyValue>>fromResult(null));
    // Watch this! ______,^   I'm writing C++ in Java!
    // Update once HBASE-2292 is fixed:
    HBaseException hbe = fakeHBaseException();
    when(client.atomicIncrement(incrementForRow(MAXID))).thenReturn(Deferred.<Long>fromError(hbe)).thenReturn(Deferred.fromResult(5L));
    when(client.compareAndSet(anyPut(), emptyArray())).thenReturn(Deferred.fromResult(true)).thenReturn(Deferred.fromResult(true));
    final byte[] id = { 0, 0, 5 };
    assertArrayEquals(id, uid.getOrCreateId("foo"));
    // Initial Get.
    verify(client, times(1)).get(anyGet());
    // First increment (failed) + retry.
    verify(client, times(2)).atomicIncrement(incrementForRow(MAXID));
    // Reverse + forward mappings.
    verify(client, times(2)).compareAndSet(anyPut(), emptyArray());
}
Also used : KeyValue(org.hbase.async.KeyValue) Config(net.opentsdb.utils.Config) HBaseException(org.hbase.async.HBaseException) TSDB(net.opentsdb.core.TSDB) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestUniqueId method getOrCreateIdAssignFilterReturnException.

@Test(expected = RuntimeException.class)
public void getOrCreateIdAssignFilterReturnException() {
    uid = new UniqueId(client, table, METRIC, 3);
    final Config config = mock(Config.class);
    when(config.enable_realtime_uid()).thenReturn(false);
    final TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    uid.setTSDB(tsdb);
    final UniqueIdFilterPlugin filter = mock(UniqueIdFilterPlugin.class);
    when(filter.fillterUIDAssignments()).thenReturn(true);
    when(filter.allowUIDAssignment(any(UniqueIdType.class), anyString(), anyString(), anyMapOf(String.class, String.class))).thenReturn(Deferred.<Boolean>fromError(new UnitTestException()));
    when(tsdb.getUidFilter()).thenReturn(filter);
    // null  =>  ID doesn't exist.
    when(client.get(anyGet())).thenReturn(Deferred.<ArrayList<KeyValue>>fromResult(null));
    // Watch this! ______,^   I'm writing C++ in Java!
    when(client.atomicIncrement(incrementForRow(MAXID))).thenReturn(Deferred.fromResult(5L));
    when(client.compareAndSet(anyPut(), emptyArray())).thenReturn(Deferred.fromResult(true)).thenReturn(Deferred.fromResult(true));
    uid.getOrCreateId("foo");
}
Also used : UnitTestException(net.opentsdb.core.BaseTsdbTest.UnitTestException) KeyValue(org.hbase.async.KeyValue) Config(net.opentsdb.utils.Config) UniqueIdType(net.opentsdb.uid.UniqueId.UniqueIdType) TSDB(net.opentsdb.core.TSDB) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with TSDB

use of net.opentsdb.core.TSDB in project opentsdb by OpenTSDB.

the class TestRpcHandler method before.

@Before
public void before() throws Exception {
    final Config config = new Config(false);
    tsdb = new TSDB(client, config);
    rpc_manager = RpcManager.instance(tsdb);
}
Also used : Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) Before(org.junit.Before)

Aggregations

TSDB (net.opentsdb.core.TSDB)43 Config (net.opentsdb.utils.Config)41 Before (org.junit.Before)16 Test (org.junit.Test)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 MockBase (net.opentsdb.storage.MockBase)13 KeyValue (org.hbase.async.KeyValue)12 ArrayList (java.util.ArrayList)11 Matchers.anyString (org.mockito.Matchers.anyString)11 UniqueIdType (net.opentsdb.uid.UniqueId.UniqueIdType)8 Field (java.lang.reflect.Field)6 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)5 IOException (java.io.IOException)4 UnitTestException (net.opentsdb.core.BaseTsdbTest.UnitTestException)4 Deferred (com.stumbleupon.async.Deferred)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 DataPoint (net.opentsdb.core.DataPoint)2 Query (net.opentsdb.core.Query)2 HBaseException (org.hbase.async.HBaseException)2