Search in sources :

Example 1 with TCommandThreadDumpResponse

use of com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_handle_serialization_of_request_events.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_handle_serialization_of_request_events() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.USER_THREAD_DUMP;
    final TCommandThreadDumpResponse expectedThreadDumpResponse = new TCommandThreadDumpResponse();
    final byte[] expectedThreadDumpResponseBody = new byte[0];
    final TCommandTransfer tCommandTransfer = new TCommandTransfer();
    tCommandTransfer.setAgentId(TEST_AGENT_ID);
    tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
    final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
    tCommandTransferResponse.setRouteResult(TRouteResult.OK);
    tCommandTransferResponse.setPayload(expectedThreadDumpResponseBody);
    final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
    when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
    when(deserializer.deserialize(expectedThreadDumpResponseBody)).thenReturn((TBase) expectedThreadDumpResponse);
    // when
    this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
    // then
    verify(this.agentEventDao, atLeast(1)).insert(argCaptor.capture());
    AgentEventBo actualAgentEventBo = argCaptor.getValue();
    assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
    assertEquals(expectedEventType, actualAgentEventBo.getEventType());
    assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody());
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Example 2 with TCommandThreadDumpResponse

use of com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse in project pinpoint by naver.

the class ThreadDumpService method requestCommandService.

@Override
public TBase<?, ?> requestCommandService(TBase<?, ?> tbase) {
    logger.info("{} execute {}.", this, tbase);
    TCommandThreadDump param = (TCommandThreadDump) tbase;
    TThreadDumpType type = param.getType();
    final List<ThreadInfo> threadInfoList = getThreadInfos(type, param);
    final List<TThreadDump> threadDumpList = getTThreadDumpList(threadInfoList);
    TCommandThreadDumpResponse response = new TCommandThreadDumpResponse();
    response.setThreadDumps(threadDumpList);
    return response;
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) TCommandThreadDump(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDump) ThreadInfo(java.lang.management.ThreadInfo) TThreadDump(com.navercorp.pinpoint.thrift.dto.command.TThreadDump) TThreadDumpType(com.navercorp.pinpoint.thrift.dto.command.TThreadDumpType)

Example 3 with TCommandThreadDumpResponse

use of com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse in project pinpoint by naver.

the class AgentEventMessageSerDesTest method createTCommandThreadDumpResponse.

private TCommandThreadDumpResponse createTCommandThreadDumpResponse() {
    final TCommandThreadDumpResponse threadDumpResponse = new TCommandThreadDumpResponse();
    ThreadInfo[] threadInfos = ThreadMXBeanUtils.dumpAllThread();
    for (ThreadInfo threadInfo : threadInfos) {
        final TThreadDump threadDump = createTThreadDump(threadInfo);
        threadDumpResponse.addToThreadDumps(threadDump);
    }
    return threadDumpResponse;
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) ThreadInfo(java.lang.management.ThreadInfo) TThreadDump(com.navercorp.pinpoint.thrift.dto.command.TThreadDump)

Example 4 with TCommandThreadDumpResponse

use of com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse in project pinpoint by naver.

the class AgentEventMessageSerDesTest method TCommandThreadDumpResponse_event_messages_should_serialize_and_deserialize_correctly.

@Test
public void TCommandThreadDumpResponse_event_messages_should_serialize_and_deserialize_correctly() throws UnsupportedEncodingException {
    final Class<TCommandThreadDumpResponse> messageTypeToTest = TCommandThreadDumpResponse.class;
    final TCommandThreadDumpResponse expectedEventMessage = createTCommandThreadDumpResponse();
    verifyEventMessageSerDer(messageTypeToTest, expectedEventMessage);
}
Also used : TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) Test(org.junit.Test)

Example 5 with TCommandThreadDumpResponse

use of com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse in project pinpoint by naver.

the class AgentEventHandlingFilterTest method handler_should_handle_serialization_of_request_events.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_handle_serialization_of_request_events() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.USER_THREAD_DUMP;
    final TCommandThreadDumpResponse expectedThreadDumpResponse = new TCommandThreadDumpResponse();
    final byte[] expectedThreadDumpResponseBody = new byte[0];
    final TCommandTransfer tCommandTransfer = new TCommandTransfer();
    tCommandTransfer.setAgentId(TEST_AGENT_ID);
    tCommandTransfer.setStartTime(TEST_START_TIMESTAMP);
    final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse();
    tCommandTransferResponse.setRouteResult(TRouteResult.OK);
    tCommandTransferResponse.setPayload(expectedThreadDumpResponseBody);
    final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    HeaderTBaseDeserializer deserializer = mock(HeaderTBaseDeserializer.class);
    when(this.deserializerFactory.createDeserializer()).thenReturn(deserializer);
    Message<TBase<?, ?>> message = new DefaultMessage<>(new HeaderV1((short) 1000), HeaderEntity.EMPTY_HEADER_ENTITY, expectedThreadDumpResponse);
    when(deserializer.deserialize(expectedThreadDumpResponseBody)).thenReturn(message);
    // when
    this.agentEventHandlingFilter.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
    // then
    verify(this.agentEventService, atLeast(1)).insert(argCaptor.capture());
    AgentEventBo actualAgentEventBo = argCaptor.getValue();
    assertEquals(TEST_AGENT_ID, actualAgentEventBo.getAgentId());
    assertEquals(TEST_START_TIMESTAMP, actualAgentEventBo.getStartTimestamp());
    assertEquals(TEST_EVENT_TIMESTAMP, actualAgentEventBo.getEventTimestamp());
    assertEquals(expectedEventType, actualAgentEventBo.getEventType());
    assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody());
}
Also used : DefaultMessage(com.navercorp.pinpoint.io.request.DefaultMessage) TCommandThreadDumpResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse) TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) HeaderV1(com.navercorp.pinpoint.io.header.v1.HeaderV1) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.event.AgentEventBo) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) TBase(org.apache.thrift.TBase) Test(org.junit.Test)

Aggregations

TCommandThreadDumpResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse)5 Test (org.junit.Test)3 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)2 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)2 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)2 ThreadInfo (java.lang.management.ThreadInfo)2 AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)1 AgentEventBo (com.navercorp.pinpoint.common.server.bo.event.AgentEventBo)1 HeaderV1 (com.navercorp.pinpoint.io.header.v1.HeaderV1)1 DefaultMessage (com.navercorp.pinpoint.io.request.DefaultMessage)1 TCommandThreadDump (com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDump)1 TThreadDumpType (com.navercorp.pinpoint.thrift.dto.command.TThreadDumpType)1 TBase (org.apache.thrift.TBase)1