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);
}
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);
}
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));
}
Aggregations