@Test public void testGenericEntityServiceResourceSearchNullDataStorage() throws IllegalAccessException, InstantiationException, IOException, IllegalDataStorageTypeException { when(DataStorageManager.getDataStorageByEagleConfig()).thenReturn(null); GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").queryParam("serviceName", "TestTimeSeriesAPIEntity").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: org.apache.eagle.storage.exception.IllegalDataStorageException: data storage is null")); verify(dataStorage, never()).queryById(any(), any()); } }
@Test public void testGenericEntityServiceResourceSearchNullServiceName() throws IllegalAccessException, InstantiationException, IOException { GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("java.lang.Exception: java.lang.IllegalArgumentException: serviceName is null")); verify(dataStorage, never()).queryById(any(), any()); }
@Test public void testGenericEntityServiceResourceupdateDatabase() throws IllegalDataStorageTypeException, IOException, IllegalAccessException, InstantiationException { TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); List<TestTimeSeriesAPIEntity> entities = new ArrayList<>(); entities.add(e); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); ModifyResult<String> modifyResult = new ModifyResult<>(); List<String> identifiers = new ArrayList<>(); identifiers.add("test"); modifyResult.setSuccess(true); modifyResult.setIdentifiers(identifiers); when(dataStorage.update(entities, ed)).thenReturn(modifyResult); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(new UpdateStatement(entities, "TestTimeSeriesAPIEntity")); Assert.assertTrue(responseEntity.isSuccess()); Assert.assertTrue(responseEntity.getMeta().toString().startsWith("{totalResults=1")); Assert.assertEquals(String.class, responseEntity.getType()); Assert.assertEquals("test", responseEntity.getObj().get(0)); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).update(entities, ed); }
@Test public void testGenericEntityServiceResourceupdateDatabaseNullDataStorage() throws IllegalDataStorageTypeException { when(DataStorageManager.getDataStorageByEagleConfig()).thenReturn(null); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(null); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertTrue(responseEntity.getException().startsWith("org.apache.eagle.storage.exception.IllegalDataStorageException: Data storage is null")); }
@Test public void testGenericEntityServiceResourceupdateDatabase1() throws IllegalDataStorageTypeException, IOException, IllegalAccessException, InstantiationException { TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); List<TestTimeSeriesAPIEntity> entities = new ArrayList<>(); entities.add(e); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); ModifyResult<String> modifyResult = new ModifyResult<>(); List<String> identifiers = null; modifyResult.setSuccess(true); modifyResult.setIdentifiers(identifiers); when(dataStorage.update(entities, ed)).thenReturn(modifyResult); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(new UpdateStatement(entities, "TestTimeSeriesAPIEntity")); Assert.assertTrue(responseEntity.isSuccess()); Assert.assertTrue(responseEntity.getMeta().toString().startsWith("{totalResults=0")); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).update(entities, ed); }
@Test public void testGenericEntityServiceResourceSearchFalse() throws IllegalAccessException, InstantiationException, IOException { QueryResult<TestTimeSeriesAPIEntity> queryResult = new QueryResult<>(); queryResult.setSuccess(false); List<String> rowkeys = new ArrayList<>(); rowkeys.add("test"); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); when(dataStorage.queryById(rowkeys, ed)).thenReturn(queryResult); GenericServiceAPIResponseEntity responseEntity = resources.client().resource("/entities/rowkey").queryParam("value", "test").queryParam("serviceName", "TestTimeSeriesAPIEntity").get(GenericServiceAPIResponseEntity.class); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).queryById(rowkeys, ed); }
Assert.assertTrue(responseEntity.getMeta().toString().startsWith("{firstTimestamp=null, totalResults=1, lastTimestamp=null, elapsedms=")); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals("{timestamp=" + timestamp + ", tags={cluster=test4UT, jobId=job_2, index=1, datacenter=dc1}, serializeVerbose=true, field1=1, field2=2, field3=3, field4=4, field5=5.0, field6=5.0, field7=7}", responseEntity.getObj().get(0).toString());
@Test public void testGenericEntityServiceResourceupdateDatabaseFalse() throws IllegalDataStorageTypeException, IOException, IllegalAccessException, InstantiationException { TestTimeSeriesAPIEntity e = new TestTimeSeriesAPIEntity(); List<TestTimeSeriesAPIEntity> entities = new ArrayList<>(); entities.add(e); EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName("TestTimeSeriesAPIEntity"); ModifyResult<String> modifyResult = new ModifyResult<>(); modifyResult.setSuccess(false); when(dataStorage.update(entities, ed)).thenReturn(modifyResult); GenericServiceAPIResponseEntity responseEntity = genericEntityServiceResource.updateDatabase(new UpdateStatement(entities, "TestTimeSeriesAPIEntity")); Assert.assertFalse(responseEntity.isSuccess()); Assert.assertEquals(null, responseEntity.getMeta()); Assert.assertEquals(null, responseEntity.getType()); Assert.assertEquals(null, responseEntity.getObj()); Assert.assertEquals(null, responseEntity.getException()); verify(dataStorage).update(entities, ed); }