use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class InternalChannelzTest method getRootChannels_onePage.
@Test
public void getRootChannels_onePage() {
InternalInstrumented<ChannelStats> root1 = create();
channelz.addRootChannel(root1);
RootChannelList page = channelz.getRootChannels(/*fromId=*/
0, /*maxPageSize=*/
1);
assertTrue(page.end);
assertThat(page.channels).containsExactly(root1);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class InternalChannelzTest method getRootChannels_onePage_multi.
@Test
public void getRootChannels_onePage_multi() {
InternalInstrumented<ChannelStats> root1 = create();
InternalInstrumented<ChannelStats> root2 = create();
channelz.addRootChannel(root1);
channelz.addRootChannel(root2);
RootChannelList page = channelz.getRootChannels(/*fromId=*/
0, /*maxPageSize=*/
2);
assertTrue(page.end);
assertThat(page.channels).containsExactly(root1, root2);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class InternalChannelzTest method getRootChannels_remove.
@Test
public void getRootChannels_remove() {
InternalInstrumented<ChannelStats> root1 = create();
channelz.addRootChannel(root1);
channelz.removeRootChannel(root1);
RootChannelList page = channelz.getRootChannels(/*fromId=*/
0, /*maxPageSize=*/
1);
assertTrue(page.end);
assertThat(page.channels).isEmpty();
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class InternalChannelzTest method getRootChannels_paginate.
@Test
public void getRootChannels_paginate() {
InternalInstrumented<ChannelStats> root1 = create();
InternalInstrumented<ChannelStats> root2 = create();
channelz.addRootChannel(root1);
channelz.addRootChannel(root2);
RootChannelList page1 = channelz.getRootChannels(/*fromId=*/
0, /*maxPageSize=*/
1);
assertFalse(page1.end);
assertThat(page1.channels).containsExactly(root1);
RootChannelList page2 = channelz.getRootChannels(/*fromId=*/
id(root1) + 1, /*maxPageSize=*/
1);
assertTrue(page2.end);
assertThat(page2.channels).containsExactly(root2);
}
use of io.grpc.InternalChannelz.ChannelStats in project grpc-java by grpc.
the class ChannelTracerTest method reportEvents.
@Test
public void reportEvents() {
ChannelTracer channelTracer = new ChannelTracer(logId, /* maxEvents= */
2, /* channelCreationTimeNanos= */
3L, "fooType");
ChannelStats.Builder builder = new ChannelStats.Builder();
Event e1 = new Event.Builder().setDescription("e1").setSeverity(Severity.CT_ERROR).setTimestampNanos(1001).build();
Event e2 = new Event.Builder().setDescription("e2").setSeverity(Severity.CT_INFO).setTimestampNanos(1002).build();
Event e3 = new Event.Builder().setDescription("e3").setSeverity(Severity.CT_WARNING).setTimestampNanos(1003).build();
Event e4 = new Event.Builder().setDescription("e4").setSeverity(Severity.CT_UNKNOWN).setTimestampNanos(1004).build();
// Check Channelz
channelTracer.updateBuilder(builder);
ChannelStats stats = builder.build();
assertThat(stats.channelTrace.events).hasSize(1);
Event creationEvent = stats.channelTrace.events.get(0);
assertThat(stats.channelTrace.numEventsLogged).isEqualTo(1);
channelTracer.reportEvent(e1);
channelTracer.updateBuilder(builder);
stats = builder.build();
assertThat(stats.channelTrace.events).containsExactly(creationEvent, e1);
assertThat(stats.channelTrace.numEventsLogged).isEqualTo(2);
channelTracer.reportEvent(e2);
channelTracer.updateBuilder(builder);
stats = builder.build();
assertThat(stats.channelTrace.events).containsExactly(e1, e2);
assertThat(stats.channelTrace.numEventsLogged).isEqualTo(3);
channelTracer.reportEvent(e3);
channelTracer.updateBuilder(builder);
stats = builder.build();
assertThat(stats.channelTrace.events).containsExactly(e2, e3);
assertThat(stats.channelTrace.numEventsLogged).isEqualTo(4);
channelTracer.reportEvent(e4);
channelTracer.updateBuilder(builder);
stats = builder.build();
assertThat(stats.channelTrace.events).containsExactly(e3, e4);
assertThat(stats.channelTrace.numEventsLogged).isEqualTo(5);
// Check logs
assertThat(logs).hasSize(5);
LogRecord log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "fooType created");
assertThat(log.getLevel()).isEqualTo(Level.FINEST);
log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "e1");
assertThat(log.getLevel()).isEqualTo(Level.FINE);
log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "e2");
assertThat(log.getLevel()).isEqualTo(Level.FINEST);
log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "e3");
assertThat(log.getLevel()).isEqualTo(Level.FINER);
log = logs.remove(0);
assertThat(log.getMessage()).isEqualTo(logPrefix + "e4");
assertThat(log.getLevel()).isEqualTo(Level.FINEST);
}
Aggregations