Search in sources :

Example 6 with NoSuchUniqueName

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

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());
            }
        });
    }
}
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 8 with NoSuchUniqueName

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());
            }
        });
    }
}
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 9 with NoSuchUniqueName

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

Example 10 with NoSuchUniqueName

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

Aggregations

NoSuchUniqueName (net.opentsdb.uid.NoSuchUniqueName)26 Test (org.junit.Test)9 Deferred (com.stumbleupon.async.Deferred)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 HashMap (java.util.HashMap)7 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)6 DeferredGroupException (com.stumbleupon.async.DeferredGroupException)5 TSDB (net.opentsdb.core.TSDB)5 Config (net.opentsdb.utils.Config)5 Before (org.junit.Before)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 MockBase (net.opentsdb.storage.MockBase)4 Callback (com.stumbleupon.async.Callback)3 IOException (java.io.IOException)3 HBaseException (org.hbase.async.HBaseException)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 List (java.util.List)2 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)2