@Test public void testGetLimitDeeper() throws IOException { jsondb.update("/test", mapper.writeValueAsString(map( "user1/value", "test 1", "user2/value", "test 2", "user3/value", "test 3", "user4/value", "test 4", "user5/value", "test 5", "user6/value", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().limitToFirst(3)); assertThat(json).isEqualTo("{\"user1\":{\"value\":\"test 1\"},\"user2\":{\"value\":\"test 2\"},\"user3\":{\"value\":\"test 3\"}}"); }
@Test public void testGetLimitDeeper() throws IOException { jsondb.update("/test", mapper.writeValueAsString(map( "user1/value", "test 1", "user2/value", "test 2", "user3/value", "test 3", "user4/value", "test 4", "user5/value", "test 5", "user6/value", "test 6" ))); String json = jsondb.getAsString("/test", new GetOptions().limitToFirst(3)); assertThat(json).isEqualTo("{\"user1\":{\"value\":\"test 1\"},\"user2\":{\"value\":\"test 2\"},\"user3\":{\"value\":\"test 3\"}}"); }
@Test public void testUpdate() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); // Verify that only the name fields change and the we can use // a path for the keys. jsondb.update("/test", mapper.writeValueAsString(map( "name", "Ana Chirino", "props/city", "Miami" ))); String json = jsondb.getAsString("/test"); assertThat(json).isEqualTo("{\"name\":\"Ana Chirino\",\"props\":{\"city\":\"Miami\",\"state\":\"FL\"}}"); jsondb.update("/test", mapper.writeValueAsString(map( "props", null ))); json = jsondb.getAsString("/test"); assertThat(json).isEqualTo("{\"name\":\"Ana Chirino\",\"props\":null}"); }
@Test public void testUpdate() throws IOException { jsondb.set("/test", mapper.writeValueAsString(map( "name", "Hiram Chirino", "props", map( "city", "Tampa", "state", "FL" ) ))); // Verify that only the name fields change and the we can use // a path for the keys. jsondb.update("/test", mapper.writeValueAsString(map( "name", "Ana Chirino", "props/city", "Miami" ))); String json = jsondb.getAsString("/test"); assertThat(json).isEqualTo("{\"name\":\"Ana Chirino\",\"props\":{\"city\":\"Miami\",\"state\":\"FL\"}}"); jsondb.update("/test", mapper.writeValueAsString(map( "props", null ))); json = jsondb.getAsString("/test"); assertThat(json).isEqualTo("{\"name\":\"Ana Chirino\",\"props\":null}"); }
@Test public void testDeadPodCurator() throws IOException, ParseException { String integrationId = "intId1"; MetricsCollector collector = new MetricsCollector(null, jsondb, null); //Update pod1 metrics and kill pod1 Set<String> livePodIds = new HashSet<String>( Arrays.asList("pod2", "pod3", "pod4", "pod5")); jsondb.update(JsonDBRawMetrics.path("intId1","pod1"), Json.writer().writeValueAsString(raw("intId1","1","pod1",12L,"31-01-2018 10:22:56"))); Map<String,RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId); IntegrationMetricsSummary summary = intMH .compute(integrationId, metrics, livePodIds); assertThat(summary.getMessages()).isEqualTo(18); assertThat(summary.getErrors()).isEqualTo(3); //Oldest living pod is now pod2 assertThat(summary.getStart().get()).isEqualTo(sdf.parse("31-01-2018 10:22:56")); collector.close(); }
@Test public void testGetIntegrationSummary() throws IOException, ParseException { String integrationId = "intId1"; Set<String> livePodIds = new HashSet<String>( Arrays.asList("pod1", "pod2", "pod3", "pod4", "pod5")); MetricsCollector collector = new MetricsCollector(null, jsondb, null); Map<String,RawMetrics> metrics = jsondbRM.getRawMetrics(integrationId); IntegrationMetricsSummary summary = intMH .compute(integrationId, metrics, livePodIds); assertThat(summary.getMessages()).isEqualTo(9); assertThat(summary.getErrors()).isEqualTo(3); //Oldest living pod assertThat(summary.getStart().get()).isEqualTo(sdf.parse("31-01-2018 10:20:56")); //Update pod2, add 6 messages jsondb.update(JsonDBRawMetrics.path("intId1","pod2"), Json.writer().writeValueAsString(raw("intId1","2","pod2",9L,"31-01-2018 10:22:56"))); Map<String,RawMetrics> updatedMetrics = jsondbRM.getRawMetrics(integrationId); IntegrationMetricsSummary updatedSummary = intMH .compute(integrationId, updatedMetrics, livePodIds); assertThat(updatedSummary.getMessages()).isEqualTo(15); assertThat(updatedSummary.getErrors()).isEqualTo(3); collector.close(); }