use of net.opentsdb.uid.NoSuchUniqueId in project opentsdb by OpenTSDB.
the class BaseTsdbTest method setupTagkMaps.
/** Adds the static UIDs to the tag keys UID mock object */
void setupTagkMaps() {
when(tag_names.getId(TAGK_STRING)).thenReturn(TAGK_BYTES);
when(tag_names.getOrCreateId(TAGK_STRING)).thenReturn(TAGK_BYTES);
when(tag_names.getIdAsync(TAGK_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGK_BYTES);
}
});
when(tag_names.getOrCreateIdAsync(TAGK_STRING)).thenReturn(Deferred.fromResult(TAGK_BYTES));
when(tag_names.getId(TAGK_B_STRING)).thenReturn(TAGK_B_BYTES);
when(tag_names.getOrCreateId(TAGK_B_STRING)).thenReturn(TAGK_B_BYTES);
when(tag_names.getIdAsync(TAGK_B_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGK_B_BYTES);
}
});
when(tag_names.getOrCreateIdAsync(TAGK_B_STRING)).thenReturn(Deferred.fromResult(TAGK_B_BYTES));
when(tag_names.getNameAsync(TAGK_BYTES)).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGK_STRING);
}
});
when(tag_names.getNameAsync(TAGK_B_BYTES)).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGK_B_STRING);
}
});
when(tag_names.getNameAsync(NSUI_TAGK)).thenThrow(new NoSuchUniqueId("tagk", NSUI_TAGK));
final NoSuchUniqueName nsun = new NoSuchUniqueName(NSUN_TAGK, "tagk");
when(tag_names.getId(NSUN_TAGK)).thenThrow(nsun);
when(tag_names.getIdAsync(NSUN_TAGK)).thenReturn(Deferred.<byte[]>fromError(nsun));
// Iterate over the tagk UIDs and handle both forward and reverse
for (final Map.Entry<String, byte[]> uid : TAGK_UIDS.entrySet()) {
when(tag_names.getId(uid.getKey())).thenReturn(uid.getValue());
when(tag_names.getIdAsync(uid.getKey())).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(uid.getValue());
}
});
when(tag_names.getOrCreateId(uid.getKey())).thenReturn(uid.getValue());
when(tag_names.getNameAsync(uid.getValue())).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(uid.getKey());
}
});
}
}
use of net.opentsdb.uid.NoSuchUniqueId in project opentsdb by OpenTSDB.
the class TestTsdbQueryQueries method runTSUIDQueryNSU.
@Test(expected = NoSuchUniqueId.class)
public void runTSUIDQueryNSU() throws Exception {
when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenThrow(new NoSuchUniqueId("metrics", new byte[] { 0, 0, 1 }));
storeLongTimeSeriesSeconds(true, false);
query.setStartTime(1356998400);
query.setEndTime(1357041600);
final List<String> tsuids = new ArrayList<String>(1);
tsuids.add("000001000001000001");
query.setTimeSeries(tsuids, Aggregators.SUM, false);
final DataPoints[] dps = query.run();
assertNotNull(dps);
dps[0].metricName();
}
use of net.opentsdb.uid.NoSuchUniqueId in project opentsdb by OpenTSDB.
the class TestTSDB method setGetUidName.
/**
* Helper to mock the UID caches with valid responses
*/
private void setGetUidName() {
when(metrics.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("sys.cpu.0"));
when(metrics.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("metric", new byte[] { 0, 0, 2 }));
when(tag_names.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("host"));
when(tag_names.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tagk", new byte[] { 0, 0, 2 }));
when(tag_values.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("web01"));
when(tag_values.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tag_values", new byte[] { 0, 0, 2 }));
}
use of net.opentsdb.uid.NoSuchUniqueId in project opentsdb by OpenTSDB.
the class TestTags method setupResolveIds.
private void setupResolveIds() throws Exception {
when(tag_names.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("host"));
when(tag_names.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tagk", new byte[] { 0, 0, 2 }));
when(tag_values.getNameAsync(new byte[] { 0, 0, 1 })).thenReturn(Deferred.fromResult("web01"));
when(tag_values.getNameAsync(new byte[] { 0, 0, 2 })).thenThrow(new NoSuchUniqueId("tagv", new byte[] { 0, 0, 2 }));
}
use of net.opentsdb.uid.NoSuchUniqueId in project opentsdb by OpenTSDB.
the class TestFsck method noSuchTagIdFix.
@SuppressWarnings("unchecked")
@Test
public void noSuchTagIdFix() throws Exception {
when(options.fix()).thenReturn(true);
when(options.deleteOrphans()).thenReturn(true);
when(Tags.resolveIds((TSDB) any(), (ArrayList<byte[]>) any())).thenThrow(new NoSuchUniqueId("tagk", new byte[] { 0, 0, 1 }));
final byte[] qual1 = { 0x00, 0x07 };
final byte[] val1 = Bytes.fromLong(4L);
final byte[] qual2 = { 0x00, 0x27 };
final byte[] val2 = new byte[] { 0, 0, 0, 0, 0, 0, 0, 5 };
storage.addColumn(ROW, qual1, val1);
storage.addColumn(ROW, qual2, val2);
final Fsck fsck = new Fsck(tsdb, options);
fsck.runFullTable();
assertEquals(0, fsck.kvs_processed.get());
assertEquals(0, fsck.rows_processed.get());
assertEquals(1, fsck.totalErrors());
assertEquals(1, fsck.correctable());
assertNull(storage.getColumn(ROW, qual1));
}
Aggregations