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