Search in sources :

Example 6 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_handle_serialization_of_messages_appropriately.

@Test
public void handler_should_handle_serialization_of_messages_appropriately() throws Exception {
    // given
    final AgentEventType expectedEventType = AgentEventType.OTHER;
    final String expectedMessageBody = "test event message";
    final byte[] expectedMessageBodyBytes = BytesUtils.toBytes(expectedMessageBody);
    ArgumentCaptor<AgentEventBo> argCaptor = ArgumentCaptor.forClass(AgentEventBo.class);
    when(this.agentEventMessageSerializer.serialize(expectedEventType, expectedMessageBody)).thenReturn(expectedMessageBodyBytes);
    // when
    this.agentEventHandler.handleEvent(this.pinpointServer, TEST_EVENT_TIMESTAMP, expectedEventType, expectedMessageBody);
    verify(this.agentEventDao, times(1)).insert(argCaptor.capture());
    // then
    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());
    assertEquals(expectedMessageBodyBytes, actualAgentEventBo.getEventBody());
}
Also used : AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) Test(org.junit.Test)

Example 7 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo 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 8 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventHandlerTest method handler_should_ignore_request_events_with_unsupported_message_types.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void handler_should_ignore_request_events_with_unsupported_message_types() throws Exception {
    // given
    final TCommandEcho mismatchingResponse = new TCommandEcho();
    final byte[] mismatchingResponseBody = 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(mismatchingResponseBody);
    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(mismatchingResponseBody)).thenReturn((TBase) mismatchingResponse);
    // when
    this.agentEventHandler.handleResponseEvent(responseEvent, TEST_EVENT_TIMESTAMP);
    // then
    verify(this.agentEventDao, never()).insert(argCaptor.capture());
}
Also used : TCommandTransfer(com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer) TCommandTransferResponse(com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) TCommandEcho(com.navercorp.pinpoint.thrift.dto.command.TCommandEcho) ResponseEvent(com.navercorp.pinpoint.collector.cluster.route.ResponseEvent) HeaderTBaseDeserializer(com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer) Test(org.junit.Test)

Example 9 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventResultsExtractor method extractData.

@Override
public List<AgentEventBo> extractData(ResultScanner results) throws Exception {
    List<AgentEventBo> agentEvents = new ArrayList<>();
    int rowNum = 0;
    for (Result result : results) {
        List<AgentEventBo> intermediateEvents = agentEventMapper.mapRow(result, rowNum++);
        if (!intermediateEvents.isEmpty()) {
            agentEvents.addAll(intermediateEvents);
        }
    }
    return agentEvents;
}
Also used : AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Example 10 with AgentEventBo

use of com.navercorp.pinpoint.common.server.bo.AgentEventBo in project pinpoint by naver.

the class AgentEventMapper method mapRow.

@Override
public List<AgentEventBo> mapRow(Result result, int rowNum) throws Exception {
    if (result.isEmpty()) {
        return Collections.emptyList();
    }
    List<AgentEventBo> agentEvents = new ArrayList<>();
    for (Cell cell : result.rawCells()) {
        byte[] qualifier = CellUtil.cloneQualifier(cell);
        final AgentEventType eventType = AgentEventType.getTypeByCode(BytesUtils.bytesToInt(qualifier, 0));
        if (eventType == null) {
            continue;
        }
        byte[] value = CellUtil.cloneValue(cell);
        final Buffer buffer = new FixedBuffer(value);
        final int version = buffer.readInt();
        switch(version) {
            case 0:
                final String agentId = buffer.readPrefixedString();
                final long startTimestamp = buffer.readLong();
                final long eventTimestamp = buffer.readLong();
                final byte[] eventMessage = buffer.readPrefixedBytes();
                final AgentEventBo agentEvent = new AgentEventBo(version, agentId, startTimestamp, eventTimestamp, eventType);
                agentEvent.setEventBody(eventMessage);
                agentEvents.add(agentEvent);
                break;
            default:
                break;
        }
    }
    return agentEvents;
}
Also used : FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) Buffer(com.navercorp.pinpoint.common.buffer.Buffer) AgentEventType(com.navercorp.pinpoint.common.server.util.AgentEventType) FixedBuffer(com.navercorp.pinpoint.common.buffer.FixedBuffer) AgentEventBo(com.navercorp.pinpoint.common.server.bo.AgentEventBo) ArrayList(java.util.ArrayList) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

AgentEventBo (com.navercorp.pinpoint.common.server.bo.AgentEventBo)10 AgentEventType (com.navercorp.pinpoint.common.server.util.AgentEventType)7 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 ResponseEvent (com.navercorp.pinpoint.collector.cluster.route.ResponseEvent)2 TCommandTransfer (com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer)2 TCommandTransferResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse)2 HeaderTBaseDeserializer (com.navercorp.pinpoint.thrift.io.HeaderTBaseDeserializer)2 AgentEvent (com.navercorp.pinpoint.web.vo.AgentEvent)2 DurationalAgentEvent (com.navercorp.pinpoint.web.vo.DurationalAgentEvent)2 Buffer (com.navercorp.pinpoint.common.buffer.Buffer)1 FixedBuffer (com.navercorp.pinpoint.common.buffer.FixedBuffer)1 TCommandEcho (com.navercorp.pinpoint.thrift.dto.command.TCommandEcho)1 TCommandThreadDumpResponse (com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse)1 PriorityQueue (java.util.PriorityQueue)1 Cell (org.apache.hadoop.hbase.Cell)1 Result (org.apache.hadoop.hbase.client.Result)1 Scan (org.apache.hadoop.hbase.client.Scan)1 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)1 FilterList (org.apache.hadoop.hbase.filter.FilterList)1