Search in sources :

Example 11 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method fixFloatingPoint.

@Test
public void fixFloatingPoint() throws Exception {
    // Check that the compaction process is fixing incorrectly encoded
    // floating point values.
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    // Note: here the flags pretend the value is on 4 bytes, but it's actually
    // on 8 bytes, so we expect the code to fix the flags as it's compacting.
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    kvs.add(makekv(qual1, val1));
    // +1s, float, 4 bytes.
    final byte[] qual2 = { 0x00, 0x1B };
    final byte[] val2 = Bytes.fromLong(Float.floatToRawIntBits(4.2F));
    final byte[] cval2 = Bytes.fromInt(Float.floatToRawIntBits(4.2F));
    kvs.add(makekv(qual2, val2));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual1, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, cval2, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual2), MockBase.concatByteArrays(val1, cval2, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual2 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method fixQualifierFlags.

@Test
public void fixQualifierFlags() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    // Note: here the flags pretend the value is on 4 bytes, but it's actually
    // on 8 bytes, so we expect the code to fix the flags as it's compacting.
    // Pretends 4 bytes...
    final byte[] qual1 = { 0x00, 0x03 };
    // ... 8 bytes actually.
    final byte[] val1 = Bytes.fromLong(4L);
    // Should have been this.
    final byte[] cqual1 = { 0x00, 0x07 };
    kvs.add(makekv(qual1, val1));
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    kvs.add(makekv(qual2, val2));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(cqual1, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val2, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(cqual1, qual2), MockBase.concatByteArrays(val1, val2, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual2 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method bigRowMs.

@Test
public void bigRowMs() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(3599999);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    byte[] qualifiers = new byte[] {};
    byte[] values = new byte[] {};
    for (int i = 0; i < 3599999; i++) {
        final int qualifier = (((i << Const.MS_FLAG_BITS) | 0x07) | 0xF0000000);
        kvs.add(makekv(Bytes.fromInt(qualifier), Bytes.fromLong(i)));
        qualifiers = MockBase.concatByteArrays(qualifiers, Bytes.fromInt(qualifier));
        values = MockBase.concatByteArrays(values, Bytes.fromLong(i));
        i += 100;
    }
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qualifiers), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(values, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, qualifiers, MockBase.concatByteArrays(values, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete((byte[]) any(), (byte[][]) any());
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method secondCompact.

@Test
public void secondCompact() throws Exception {
    // In this test the row has already been compacted, and another data
    // point was written in the mean time.
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    // This is 2 values already compacted together.
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    final byte[] qual2 = { 0x00, 0x27 };
    final byte[] val2 = Bytes.fromLong(5L);
    final byte[] qual12 = MockBase.concatByteArrays(qual1, qual2);
    kvs.add(makekv(qual12, MockBase.concatByteArrays(val1, val2, ZERO)));
    // This data point came late.  Note that its time delta falls in between
    // that of the two data points above.
    final byte[] qual3 = { 0x00, 0x17 };
    final byte[] val3 = Bytes.fromLong(6L);
    kvs.add(makekv(qual3, val3));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual1, qual3, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val3, val2, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual3, qual2), MockBase.concatByteArrays(val1, val3, val2, ZERO));
    // And we had to delete the individual cell + pre-existing compacted cell.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual12, qual3 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with Annotation

use of net.opentsdb.meta.Annotation in project opentsdb by OpenTSDB.

the class TestCompactionQueue method twoCellRow.

@Test
public void twoCellRow() throws Exception {
    ArrayList<KeyValue> kvs = new ArrayList<KeyValue>(2);
    ArrayList<Annotation> annotations = new ArrayList<Annotation>(0);
    final byte[] qual1 = { 0x00, 0x07 };
    final byte[] val1 = Bytes.fromLong(4L);
    kvs.add(makekv(qual1, val1));
    final byte[] qual2 = { 0x00, 0x17 };
    final byte[] val2 = Bytes.fromLong(5L);
    kvs.add(makekv(qual2, val2));
    final KeyValue kv = compactionq.compact(kvs, annotations);
    assertArrayEquals(MockBase.concatByteArrays(qual1, qual2), kv.qualifier());
    assertArrayEquals(MockBase.concatByteArrays(val1, val2, ZERO), kv.value());
    // We had one row to compact, so one put to do.
    verify(tsdb, times(1)).put(KEY, MockBase.concatByteArrays(qual1, qual2), MockBase.concatByteArrays(val1, val2, ZERO));
    // And we had to delete individual cells.
    verify(tsdb, times(1)).delete(eq(KEY), eqAnyOrder(new byte[][] { qual1, qual2 }));
}
Also used : KeyValue(org.hbase.async.KeyValue) ArrayList(java.util.ArrayList) Annotation(net.opentsdb.meta.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Annotation (net.opentsdb.meta.Annotation)77 ArrayList (java.util.ArrayList)68 Test (org.junit.Test)63 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)63 KeyValue (org.hbase.async.KeyValue)50 DataPoints (net.opentsdb.core.DataPoints)18 TSQuery (net.opentsdb.core.TSQuery)15 MockDataPoints (net.opentsdb.storage.MockDataPoints)13 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)10 Matchers.anyString (org.mockito.Matchers.anyString)10 Deferred (com.stumbleupon.async.Deferred)5 IOException (java.io.IOException)5 Callback (com.stumbleupon.async.Callback)4 HashMap (java.util.HashMap)4 List (java.util.List)4 DataPoint (net.opentsdb.core.DataPoint)4 NoSuchUniqueId (net.opentsdb.uid.NoSuchUniqueId)3 Map (java.util.Map)2 IncomingDataPoint (net.opentsdb.core.IncomingDataPoint)2 Query (net.opentsdb.core.Query)2