use of co.cask.cdap.metrics.process.MetricsTableMigration in project cdap by caskdata.
the class HBaseMetricsTableTest method testDataMigration.
@Test
public void testDataMigration() throws Exception {
MetricsTable v2Table = getTable("V2Table");
MetricsTable v3Table = getTable("V3Table");
v2Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(A, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(B, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).put(X, mapOf(A, Bytes.toLong(A), B, Bytes.toLong(B))).build());
// add just column A value for key X in table v3, so this is an increment, while column B is a gauge.
v3Table.put(ImmutableSortedMap.<byte[], SortedMap<byte[], Long>>orderedBy(Bytes.BYTES_COMPARATOR).put(X, mapOf(A, Bytes.toLong(A))).build());
MetricsTableMigration metricsTableMigration = new MetricsTableMigration("V2Table", v2Table, "V3Table", v3Table);
Assert.assertTrue(isMetricsDataAvailable(v2Table));
metricsTableMigration.transferData(1);
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(A, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(A, B)));
Assert.assertEquals(Bytes.toLong(A), Bytes.toLong(v3Table.get(B, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(B, B)));
// this is an increment
Assert.assertEquals(Bytes.toLong(A) * 2, Bytes.toLong(v3Table.get(X, A)));
Assert.assertEquals(Bytes.toLong(B), Bytes.toLong(v3Table.get(X, B)));
Assert.assertFalse(isMetricsDataAvailable(v2Table));
}
Aggregations