@Before public void setUp() { try { ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestLogAPIEntity.class); if (ed == null) { EntityDefinitionManager.registerEntity(TestLogAPIEntity.class); ed = EntityDefinitionManager.getEntityDefinitionByEntityClass(TestLogAPIEntity.class); } } catch (InstantiationException e) { Assert.fail(e.getMessage()); } catch (IllegalAccessException e) { Assert.fail(e.getMessage()); } }
@Test public void testTimeSeriesAPIEntity() { InternalLog internalLog = new InternalLog(); Map<String, byte[]> map = new HashMap<String, byte[]>(); TestTimeSeriesAPIEntity apiEntity = new TestTimeSeriesAPIEntity(); EntityDefinition ed = null; try { ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } map.put("a", ByteUtil.intToBytes(12)); map.put("c", ByteUtil.longToBytes(123432432l)); map.put("cluster", new String("cluster4ut").getBytes()); map.put("datacenter", new String("datacenter4ut").getBytes()); internalLog.setQualifierValues(map); internalLog.setTimestamp(System.currentTimeMillis()); try { TaggedLogAPIEntity entity = HBaseInternalLogHelper.buildEntity(internalLog, ed); Assert.assertTrue(entity instanceof TestTimeSeriesAPIEntity); TestTimeSeriesAPIEntity tsentity = (TestTimeSeriesAPIEntity) entity; Assert.assertEquals("cluster4ut", tsentity.getTags().get("cluster")); Assert.assertEquals("datacenter4ut", tsentity.getTags().get("datacenter")); Assert.assertEquals(12, tsentity.getField1()); Assert.assertEquals(123432432l, tsentity.getField3()); } catch (Exception e) { e.printStackTrace(); } }