use of net.opentsdb.uid.NoSuchUniqueName in project opentsdb by OpenTSDB.
the class BaseTsdbTest method setupTagvMaps.
/** Adds the static UIDs to the tag values UID mock object */
void setupTagvMaps() {
when(tag_values.getId(TAGV_STRING)).thenReturn(TAGV_BYTES);
when(tag_values.getOrCreateId(TAGV_STRING)).thenReturn(TAGV_BYTES);
when(tag_values.getIdAsync(TAGV_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGV_BYTES);
}
});
when(tag_values.getOrCreateIdAsync(TAGV_STRING)).thenReturn(Deferred.fromResult(TAGV_BYTES));
when(tag_values.getId(TAGV_B_STRING)).thenReturn(TAGV_B_BYTES);
when(tag_values.getOrCreateId(TAGV_B_STRING)).thenReturn(TAGV_B_BYTES);
when(tag_values.getIdAsync(TAGV_B_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(TAGV_B_BYTES);
}
});
when(tag_values.getOrCreateIdAsync(TAGV_B_STRING)).thenReturn(Deferred.fromResult(TAGV_B_BYTES));
when(tag_values.getNameAsync(TAGV_BYTES)).thenReturn(Deferred.fromResult(TAGV_STRING));
when(tag_values.getNameAsync(TAGV_B_BYTES)).thenReturn(Deferred.fromResult(TAGV_B_STRING));
when(tag_values.getNameAsync(NSUI_TAGV)).thenThrow(new NoSuchUniqueId("tagv", NSUI_TAGV));
final NoSuchUniqueName nsun = new NoSuchUniqueName(NSUN_TAGV, "tagv");
when(tag_values.getId(NSUN_TAGV)).thenThrow(nsun);
when(tag_values.getIdAsync(NSUN_TAGV)).thenReturn(Deferred.<byte[]>fromError(nsun));
// Iterate over the tagv UIDs and handle both forward and reverse
for (final Map.Entry<String, byte[]> uid : TAGV_UIDS.entrySet()) {
when(tag_values.getId(uid.getKey())).thenReturn(uid.getValue());
when(tag_values.getIdAsync(uid.getKey())).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(uid.getValue());
}
});
when(tag_values.getOrCreateId(uid.getKey())).thenReturn(uid.getValue());
when(tag_values.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.NoSuchUniqueName in project opentsdb by OpenTSDB.
the class BaseTsdbTest method setupMetricMaps.
/** Adds the static UIDs to the metrics UID mock object */
void setupMetricMaps() {
when(metrics.getId(METRIC_STRING)).thenReturn(METRIC_BYTES);
when(metrics.getIdAsync(METRIC_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(METRIC_BYTES);
}
});
when(metrics.getOrCreateId(METRIC_STRING)).thenReturn(METRIC_BYTES);
when(metrics.getId(METRIC_B_STRING)).thenReturn(METRIC_B_BYTES);
when(metrics.getIdAsync(METRIC_B_STRING)).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(METRIC_B_BYTES);
}
});
when(metrics.getOrCreateId(METRIC_B_STRING)).thenReturn(METRIC_B_BYTES);
when(metrics.getNameAsync(METRIC_BYTES)).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(METRIC_STRING);
}
});
when(metrics.getNameAsync(METRIC_B_BYTES)).thenAnswer(new Answer<Deferred<String>>() {
@Override
public Deferred<String> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(METRIC_B_STRING);
}
});
when(metrics.getNameAsync(NSUI_METRIC)).thenThrow(new NoSuchUniqueId("metrics", NSUI_METRIC));
final NoSuchUniqueName nsun = new NoSuchUniqueName(NSUN_METRIC, "metrics");
when(metrics.getId(NSUN_METRIC)).thenThrow(nsun);
when(metrics.getIdAsync(NSUN_METRIC)).thenReturn(Deferred.<byte[]>fromError(nsun));
when(metrics.getOrCreateId(NSUN_METRIC)).thenThrow(nsun);
// Iterate over the metric UIDs and handle both forward and reverse
for (final Map.Entry<String, byte[]> uid : METRIC_UIDS.entrySet()) {
when(metrics.getId(uid.getKey())).thenReturn(uid.getValue());
when(metrics.getIdAsync(uid.getKey())).thenAnswer(new Answer<Deferred<byte[]>>() {
@Override
public Deferred<byte[]> answer(InvocationOnMock invocation) throws Throwable {
return Deferred.fromResult(uid.getValue());
}
});
when(metrics.getOrCreateId(uid.getKey())).thenReturn(uid.getValue());
when(metrics.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.NoSuchUniqueName 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.NoSuchUniqueName in project opentsdb by OpenTSDB.
the class TestTSDB method renameUidNonexistentTagk.
@Test(expected = IllegalArgumentException.class)
public void renameUidNonexistentTagk() {
when(tag_names.getId("datacenter")).thenThrow(new NoSuchUniqueName("tagk", "datacenter"));
tsdb.renameUid("tagk", "datacenter", "datacluster");
}
use of net.opentsdb.uid.NoSuchUniqueName in project opentsdb by OpenTSDB.
the class TestTSDB method assignUidTagv.
@Test
public void assignUidTagv() {
when(tag_values.getId("localhost")).thenThrow(new NoSuchUniqueName("tagv", "localhost"));
when(tag_values.getOrCreateId("localhost")).thenReturn(new byte[] { 0, 0, 2 });
assertArrayEquals(new byte[] { 0, 0, 2 }, tsdb.assignUid("tagv", "localhost"));
}
Aggregations