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);
}
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();
}
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));
}
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");
}
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;
}
Aggregations