diff --git a/collector/src/test/java/com/navercorp/pinpoint/collector/rpc/handler/AgentEventHandlerTest.java b/collector/src/test/java/com/navercorp/pinpoint/collector/rpc/handler/AgentEventHandlerTest.java index 6b819cb67e18..144abf0eb7c8 100644 --- a/collector/src/test/java/com/navercorp/pinpoint/collector/rpc/handler/AgentEventHandlerTest.java +++ b/collector/src/test/java/com/navercorp/pinpoint/collector/rpc/handler/AgentEventHandlerTest.java @@ -42,6 +42,7 @@ import com.navercorp.pinpoint.common.util.AgentEventType; import com.navercorp.pinpoint.common.util.BytesUtils; import com.navercorp.pinpoint.rpc.server.PinpointServer; +import com.navercorp.pinpoint.thrift.dto.command.TCommandEcho; import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransfer; import com.navercorp.pinpoint.thrift.dto.command.TCommandTransferResponse; @@ -66,7 +67,7 @@ public class AgentEventHandlerTest { @Mock private AgentEventMessageSerializer agentEventMessageSerializer; - + @Mock private DeserializerFactory deserializerFactory; @@ -133,10 +134,10 @@ public void handler_should_handle_serialization_of_request_events() throws Excep final TCommandTransfer tCommandTransfer = new TCommandTransfer(); tCommandTransfer.setAgentId(TEST_AGENT_ID); tCommandTransfer.setStartTime(TEST_START_TIMESTAMP); - - final TCommandTransferResponse tCommandTransferResponse = mock(TCommandTransferResponse.class); - when(tCommandTransferResponse.getRouteResult()).thenReturn(TRouteResult.OK); - when(tCommandTransferResponse.getPayload()).thenReturn(expectedThreadDumpResponseBody); + + final TCommandTransferResponse tCommandTransferResponse = new TCommandTransferResponse(); + tCommandTransferResponse.setRouteResult(TRouteResult.OK); + tCommandTransferResponse.setPayload(expectedThreadDumpResponseBody); final ResponseEvent responseEvent = new ResponseEvent(tCommandTransfer, null, 0, tCommandTransferResponse); @@ -144,17 +145,43 @@ public void handler_should_handle_serialization_of_request_events() throws Excep 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, times(1)).insert(argCaptor.capture()); + 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()); - assertEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody()); + assertArrayEquals(expectedThreadDumpResponseBody, actualAgentEventBo.getEventBody()); + } + + @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 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()); } private static Map createTestChannelProperties() { diff --git a/commons/src/test/java/com/navercorp/pinpoint/common/util/AgentEventMessageSerDesTest.java b/commons/src/test/java/com/navercorp/pinpoint/common/util/AgentEventMessageSerDesTest.java index e54d31fba5cb..96906c94f4bf 100644 --- a/commons/src/test/java/com/navercorp/pinpoint/common/util/AgentEventMessageSerDesTest.java +++ b/commons/src/test/java/com/navercorp/pinpoint/common/util/AgentEventMessageSerDesTest.java @@ -27,6 +27,7 @@ import org.apache.thrift.protocol.TProtocolFactory; import org.junit.Test; +import com.navercorp.pinpoint.common.Version; import com.navercorp.pinpoint.thrift.dto.command.TCommandThreadDumpResponse; import com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo; import com.navercorp.pinpoint.thrift.dto.command.TThreadDump; @@ -45,7 +46,7 @@ */ public class AgentEventMessageSerDesTest { - private static final String TEST_PINPOINT_VERSION = "1.0.3-SNAPSHOT"; + private static final String TEST_PINPOINT_VERSION = Version.VERSION; private final TProtocolFactory protocolFactory = new TCompactProtocol.Factory(); private final TCommandRegistry commandTbaseRegistry = new TCommandRegistry(TCommandTypeVersion.getVersion(TEST_PINPOINT_VERSION));