Search in sources :

Example 1 with LoggerBackend

use of oap.logstream.LoggerBackend in project oap by oaplatform.

the class ShardedLoggerBackendTest method testRouting.

@Test
public void testRouting() {
    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(mapper.getShardNumber(anyString(), eq("34/df/file1"), any(byte[].class))).thenReturn(34);
    when(mapper.getShardNumber(anyString(), eq("142/345/file1"), any(byte[].class))).thenReturn(142);
    slb.log("localhost", "34/df/file1", "line1");
    slb.log("localhost", "142/345/file1", "line2");
    verify(log1).log("localhost", "34/df/file1", "line1\n".getBytes(), 0, "line1\n".getBytes().length);
    verify(log2).log("localhost", "142/345/file1", "line2\n".getBytes(), 0, "line2\n".getBytes().length);
}
Also used : LoggerBackend(oap.logstream.LoggerBackend) Test(org.testng.annotations.Test)

Example 2 with LoggerBackend

use of oap.logstream.LoggerBackend in project oap by oaplatform.

the class ShardedLoggerBackendTest method testUnconfiguredShards.

@Test(expectedExceptions = NoLoggerConfiguredForShardsException.class)
public void testUnconfiguredShards() {
    LoggerBackend log1 = mock(LoggerBackend.class);
    LoggerShardRange shard0To100 = new LoggerShardRange(log1, 0, 100);
    LoggerShardRange shard100To200 = new LoggerShardRange(log1, 110, 200);
    List<LoggerShardRange> shards = Arrays.asList(shard0To100, shard100To200);
    new ShardedLoggerBackend(shards, mapper);
}
Also used : LoggerBackend(oap.logstream.LoggerBackend) Test(org.testng.annotations.Test)

Example 3 with LoggerBackend

use of oap.logstream.LoggerBackend 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

LoggerBackend (oap.logstream.LoggerBackend)3 Test (org.testng.annotations.Test)3 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 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