Search in sources :

Example 6 with NoSuchUniqueId

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());
            }
        });
    }
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) Deferred(com.stumbleupon.async.Deferred) HashMap(java.util.HashMap) Map(java.util.Map) NoSuchUniqueName(net.opentsdb.uid.NoSuchUniqueName)

Example 7 with NoSuchUniqueId

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();
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) ArrayList(java.util.ArrayList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with NoSuchUniqueId

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 }));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId)

Example 9 with NoSuchUniqueId

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 }));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId)

Example 10 with NoSuchUniqueId

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));
}
Also used : NoSuchUniqueId(net.opentsdb.uid.NoSuchUniqueId) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)17 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 Deferred (com.stumbleupon.async.Deferred)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 HashMap (java.util.HashMap)4 NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)4 DataPoints (net.opentsdb.core.DataPoints)3 TSQuery (net.opentsdb.core.TSQuery)3 Annotation (net.opentsdb.meta.Annotation)3 MockDataPoints (net.opentsdb.storage.MockDataPoints)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Callback (com.stumbleupon.async.Callback)2 List (java.util.List)2 Matchers.anyString (org.mockito.Matchers.anyString)2 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)1 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1