Search in sources :

Example 6 with ChannelStats

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);
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) RootChannelList(io.grpc.InternalChannelz.RootChannelList) Test(org.junit.Test)

Example 7 with ChannelStats

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);
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) RootChannelList(io.grpc.InternalChannelz.RootChannelList) Test(org.junit.Test)

Example 8 with ChannelStats

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();
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) RootChannelList(io.grpc.InternalChannelz.RootChannelList) Test(org.junit.Test)

Example 9 with ChannelStats

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);
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) RootChannelList(io.grpc.InternalChannelz.RootChannelList) Test(org.junit.Test)

Example 10 with ChannelStats

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);
}
Also used : ChannelStats(io.grpc.InternalChannelz.ChannelStats) LogRecord(java.util.logging.LogRecord) Event(io.grpc.InternalChannelz.ChannelTrace.Event) Test(org.junit.Test)

Aggregations

ChannelStats (io.grpc.InternalChannelz.ChannelStats)15 Test (org.junit.Test)11 Event (io.grpc.InternalChannelz.ChannelTrace.Event)5 RootChannelList (io.grpc.InternalChannelz.RootChannelList)5 InternalWithLogId (io.grpc.InternalWithLogId)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ChannelData (io.grpc.channelz.v1.ChannelData)2 LogRecord (java.util.logging.LogRecord)2 InternalChannelz (io.grpc.InternalChannelz)1 Channel (io.grpc.channelz.v1.Channel)1 ChannelTrace (io.grpc.channelz.v1.ChannelTrace)1 ChannelTraceEvent (io.grpc.channelz.v1.ChannelTraceEvent)1 GetChannelResponse (io.grpc.channelz.v1.GetChannelResponse)1 GetSubchannelResponse (io.grpc.channelz.v1.GetSubchannelResponse)1 Subchannel (io.grpc.channelz.v1.Subchannel)1 TestChannel (io.grpc.protobuf.services.ChannelzTestHelper.TestChannel)1