Search in sources :

Example 11 with TSDB

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

the class TestRpcManager method loadHttpRpcPlugins.

@Test
public void loadHttpRpcPlugins() throws Exception {
    Config config = mock(Config.class);
    when(config.hasProperty("tsd.http.rpc.plugins")).thenReturn(true);
    when(config.getString("tsd.http.rpc.plugins")).thenReturn("net.opentsdb.tsd.DummyHttpRpcPlugin");
    when(config.getString("tsd.core.enable_api")).thenReturn("true");
    when(config.getString("tsd.core.enable_ui")).thenReturn("true");
    when(config.getString("tsd.no_diediedie")).thenReturn("false");
    TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    PluginLoader.loadJAR("plugin_test.jar");
    mgr_under_test = RpcManager.instance(tsdb);
    HttpRpcPlugin plugin = mgr_under_test.lookupHttpRpcPlugin("dummy/test");
    assertNotNull(plugin);
}
Also used : Config(net.opentsdb.utils.Config) TSDB(net.opentsdb.core.TSDB) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with TSDB

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

the class TestUniqueId method getOrCreateIdAsyncAssignFilterReturnException.

@Test(expected = UnitTestException.class)
public void getOrCreateIdAsyncAssignFilterReturnException() 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.<Boolean>fromError(new UnitTestException()));
    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 : 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 13 with TSDB

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

the class TestUniqueId method getOrCreateIdAsyncAssignFilterOK.

@Test
public void getOrCreateIdAsyncAssignFilterOK() throws Exception {
    uid = new UniqueId(client, table, METRIC, 3);
    final byte[] id = { 0, 0, 5 };
    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(true));
    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));
    assertArrayEquals(id, uid.getOrCreateIdAsync("foo").join());
    // Should be a cache hit since we created that entry.
    assertArrayEquals(id, uid.getOrCreateIdAsync("foo").join());
    // Should be a cache hit too for the same reason.
    assertEquals("foo", uid.getName(id));
    // Initial Get.
    verify(client).get(anyGet());
    verify(client).atomicIncrement(incrementForRow(MAXID));
    // Reverse + forward mappings.
    verify(client, times(2)).compareAndSet(anyPut(), emptyArray());
    verify(filter, times(1)).allowUIDAssignment(any(UniqueIdType.class), anyString(), anyString(), anyMapOf(String.class, String.class));
}
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 14 with TSDB

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

the class TestUniqueId method getOrCreateIdAssignFilterBlocked.

@Test(expected = FailedToAssignUniqueIdException.class)
public void getOrCreateIdAssignFilterBlocked() {
    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));
    // 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 : 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 15 with TSDB

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

the class TestRpcManager method before.

@Before
public void before() {
    Config config = mock(Config.class);
    when(config.getString("tsd.core.enable_api")).thenReturn("true");
    when(config.getString("tsd.core.enable_ui")).thenReturn("true");
    when(config.getString("tsd.no_diediedie")).thenReturn("false");
    TSDB tsdb = mock(TSDB.class);
    when(tsdb.getConfig()).thenReturn(config);
    mock_tsdb_no_plugins = 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