public Identifier getIdentifier() { if (real == null) { return identifier; } else { return real.getIdentifier(); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof TimelineEntity)) { return false; } TimelineEntity other = (TimelineEntity) obj; return getIdentifier().equals(other.getIdentifier()); }
@Override public int hashCode() { return getIdentifier().hashCode(); }
@Test public void testGetEntityAllFields() throws Exception { // All fields of TimelineEntity will be returned. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.ALL), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); // All fields including events will be returned. Assert.assertEquals(2, result.getEvents().size()); }
@Test public void testGetEntityCustomFields() throws Exception { // Specified fields in addition to default view will be returned. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, EnumSet.of(Field.INFO, Field.CONFIGS, Field.METRICS), null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(3, result.getConfigs().size()); Assert.assertEquals(3, result.getMetrics().size()); Assert.assertEquals(2, result.getInfo().size()); // No events will be returned Assert.assertEquals(0, result.getEvents().size()); }
@Test public void testGetEntityDefaultView() throws Exception { // If no fields are specified, entity is returned with default view i.e. // only the id, type and created time. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", "user1", "flow1", 1L, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
@Test public void testGetEntityByClusterAndApp() throws Exception { // Cluster and AppId should be enough to get an entity. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app1", "app", "id_1"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_1")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502000L, result.getCreatedTime()); Assert.assertEquals(0, result.getConfigs().size()); Assert.assertEquals(0, result.getMetrics().size()); }
/** This test checks whether we can handle commas in app flow mapping csv. */ @Test public void testAppFlowMappingCsv() throws Exception { // Test getting an entity by cluster and app where flow entry // in app flow mapping csv has commas. TimelineEntity result = reader.getEntity( new TimelineReaderContext("cluster1", null, null, null, "app2", "app", "id_5"), new TimelineDataToRetrieve(null, null, null, null, null, null)); Assert.assertEquals( (new TimelineEntity.Identifier("app", "id_5")).toString(), result.getIdentifier().toString()); Assert.assertEquals((Long)1425016502050L, result.getCreatedTime()); }