Search in sources :

Example 1 with PARTIALLY_OPERATIONAL

use of oap.logstream.AvailabilityReport.State.PARTIALLY_OPERATIONAL in project oap by oaplatform.

the class ShardedLoggerBackendTest method testAvailability.

@Test
public void testAvailability() {
    LoggerBackend log1 = mock(LoggerBackend.class);
    LoggerBackend log2 = mock(LoggerBackend.class);
    LoggerShardRange shard0To100 = new LoggerShardRange(log1, 0, 100);
    LoggerShardRange shard100To200 = new LoggerShardRange(log2, 100, 200);
    List<LoggerShardRange> shards = Arrays.asList(shard0To100, shard100To200);
    ShardedLoggerBackend slb = new ShardedLoggerBackend(shards, mapper);
    when(log1.availabilityReport()).thenReturn(new AvailabilityReport(OPERATIONAL));
    when(log2.availabilityReport()).thenReturn(new AvailabilityReport(OPERATIONAL));
    assertEquals(slb.availabilityReport().state, OPERATIONAL);
    assertEquals(slb.availabilityReport().subsystemStates.size(), 2);
    assertTrue(Stream.of(slb.availabilityReport().subsystemStates.values()).allMatch(s -> s == OPERATIONAL));
    when(log1.availabilityReport()).thenReturn(new AvailabilityReport(FAILED));
    when(log2.availabilityReport()).thenReturn(new AvailabilityReport(FAILED));
    assertEquals(slb.availabilityReport().state, FAILED);
    assertEquals(slb.availabilityReport().subsystemStates.size(), 2);
    assertTrue(Stream.of(slb.availabilityReport().subsystemStates.values()).allMatch(s -> s == FAILED));
    when(log1.availabilityReport()).thenReturn(new AvailabilityReport(OPERATIONAL));
    when(log2.availabilityReport()).thenReturn(new AvailabilityReport(FAILED));
    assertEquals(slb.availabilityReport().state, PARTIALLY_OPERATIONAL);
    assertEquals(slb.availabilityReport().subsystemStates.size(), 2);
    assertTrue(slb.availabilityReport().subsystemStates.values().contains(OPERATIONAL));
    assertTrue(slb.availabilityReport().subsystemStates.values().contains(FAILED));
}
Also used : Arrays(java.util.Arrays) PARTIALLY_OPERATIONAL(oap.logstream.AvailabilityReport.State.PARTIALLY_OPERATIONAL) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Mockito.when(org.mockito.Mockito.when) Matchers.anyString(org.mockito.Matchers.anyString) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) List(java.util.List) NoLoggerConfiguredForShardsException(oap.logstream.NoLoggerConfiguredForShardsException) OPERATIONAL(oap.logstream.AvailabilityReport.State.OPERATIONAL) Matchers.eq(org.mockito.Matchers.eq) AvailabilityReport(oap.logstream.AvailabilityReport) LoggerBackend(oap.logstream.LoggerBackend) Assert.assertTrue(org.testng.Assert.assertTrue) Stream(oap.util.Stream) FAILED(oap.logstream.AvailabilityReport.State.FAILED) Mockito.mock(org.mockito.Mockito.mock) AvailabilityReport(oap.logstream.AvailabilityReport) LoggerBackend(oap.logstream.LoggerBackend) Test(org.testng.annotations.Test)

Aggregations

Arrays (java.util.Arrays)1 List (java.util.List)1 AvailabilityReport (oap.logstream.AvailabilityReport)1 FAILED (oap.logstream.AvailabilityReport.State.FAILED)1 OPERATIONAL (oap.logstream.AvailabilityReport.State.OPERATIONAL)1 PARTIALLY_OPERATIONAL (oap.logstream.AvailabilityReport.State.PARTIALLY_OPERATIONAL)1 LoggerBackend (oap.logstream.LoggerBackend)1 NoLoggerConfiguredForShardsException (oap.logstream.NoLoggerConfiguredForShardsException)1 Stream (oap.util.Stream)1 Matchers.any (org.mockito.Matchers.any)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Matchers.eq (org.mockito.Matchers.eq)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 Assert.assertEquals (org.testng.Assert.assertEquals)1 Assert.assertTrue (org.testng.Assert.assertTrue)1 Test (org.testng.annotations.Test)1