This is an automated email from the ASF dual-hosted git repository. aldettinger pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 6f057bb Added route level tests to camel-ganglia by mocking the gmond agent 6f057bb is described below commit 6f057bbc04a6ae0f7abf786aebccae794875a747 Author: aldettinger <aldettin...@gmail.com> AuthorDate: Sat Apr 21 14:45:37 2018 +0200 Added route level tests to camel-ganglia by mocking the gmond agent --- components/camel-ganglia/pom.xml | 5 + .../component/ganglia/CamelGangliaTestSupport.java | 8 +- .../camel/component/ganglia/GangliaCamelTest.java | 72 ------ .../ganglia/GangliaConfigurationTest.java | 2 - .../ganglia/GangliaProtocolV30CamelTest.java | 168 +++++++++++++ .../ganglia/GangliaProtocolV31CamelTest.java | 259 +++++++++++++++++++++ 6 files changed, 436 insertions(+), 78 deletions(-) diff --git a/components/camel-ganglia/pom.xml b/components/camel-ganglia/pom.xml index bf6c5d4..998b908 100644 --- a/components/camel-ganglia/pom.xml +++ b/components/camel-ganglia/pom.xml @@ -62,6 +62,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-netty4</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java index 6cd170e..7f165ec 100644 --- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java +++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/CamelGangliaTestSupport.java @@ -18,13 +18,13 @@ package org.apache.camel.component.ganglia; import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.BeforeClass; +import org.junit.Before; public class CamelGangliaTestSupport extends CamelTestSupport { - private static int testPort; + private int testPort; - @BeforeClass - public static void setup() { + @Before + public void setup() { testPort = AvailablePortFinder.getNextAvailable(); } diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java deleted file mode 100644 index 139ade0..0000000 --- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaCamelTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.ganglia; - -import java.util.HashMap; -import java.util.Map; - -import info.ganglia.gmetric4j.gmetric.GMetricSlope; -import info.ganglia.gmetric4j.gmetric.GMetricType; - -import org.apache.camel.ResolveEndpointFailedException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -/** - * {@code GangliaCamelTest} is not shipped with an embedded gmond agent, as such - * datagrams sent by the camel-ganglia component during those tests are simply - * dropped at UDP level. - */ -public class GangliaCamelTest extends CamelGangliaTestSupport { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private String getTestUri() { - return "ganglia:localhost:" + getTestPort() + "?mode=UNICAST&metricName=temperature&type=Double"; - } - - @Test - public void sendShouldNotThrow() { - template.sendBody(getTestUri(), 28.0); - } - - @Test - public void sendUsingWireFormat30xShouldNotThrow() { - template.sendBody(getTestUri() + "&wireFormat31x=false", 28.0); - } - - @Test - public void sendMessageHeadersOverridingEndpointOptionsShouldNotThrow() { - Map<String, Object> headers = new HashMap<>(); - headers.put(GangliaConstants.GROUP_NAME, "sea-mesure"); - headers.put(GangliaConstants.METRIC_NAME, "depth"); - headers.put(GangliaConstants.METRIC_TYPE, GMetricType.FLOAT); - headers.put(GangliaConstants.METRIC_SLOPE, GMetricSlope.NEGATIVE); - headers.put(GangliaConstants.METRIC_UNITS, "cm"); - headers.put(GangliaConstants.METRIC_TMAX, 100); - headers.put(GangliaConstants.METRIC_DMAX, 10); - template.sendBodyAndHeaders(getTestUri(), -3.0f, headers); - } - - @Test - public void sendWithWrongTypeShouldThrow() { - thrown.expect(ResolveEndpointFailedException.class); - template.sendBody(getTestUri() + "&type=wrong", ""); - } -} diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaConfigurationTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaConfigurationTest.java index 5ce86b7..018a95c 100644 --- a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaConfigurationTest.java +++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaConfigurationTest.java @@ -26,8 +26,6 @@ import static org.junit.Assert.assertEquals; /** * JUnit test class for <code>org.apache.camel.component.ganglia.GangliaConfiguration</code> - * - * @version */ public class GangliaConfigurationTest { diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java new file mode 100644 index 0000000..4ff8f99 --- /dev/null +++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV30CamelTest.java @@ -0,0 +1,168 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.ganglia; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import info.ganglia.gmetric4j.xdr.v30x.Ganglia_message; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; +import io.netty.handler.codec.MessageToMessageDecoder; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrBufferDecodingStream; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static info.ganglia.gmetric4j.gmetric.GMetricSlope.NEGATIVE; +import static info.ganglia.gmetric4j.gmetric.GMetricType.FLOAT; + +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_DMAX; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_METRIC_NAME; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_SLOPE; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_TMAX; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_TYPE; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_UNITS; + +import static org.apache.camel.component.ganglia.GangliaConstants.GROUP_NAME; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_DMAX; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_NAME; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_SLOPE; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TMAX; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TYPE; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS; + +/** + * {@code GangliaProtocolV30CamelTest} is not shipped with an embedded gmond + * agent. The gmond agent is mocked with the help of camel-netty4 codecs and a + * mock endpoint. As underlying UDP packets are not guaranteed to be delivered, + * loose assertions are performed. + */ +public class GangliaProtocolV30CamelTest extends CamelGangliaTestSupport { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @EndpointInject(uri = "mock:gmond") + private MockEndpoint mockGmond; + + private String getTestUri() { + return "ganglia:localhost:" + getTestPort() + "?mode=UNICAST&wireFormat31x=false"; + } + + @Test + public void sendDefaultConfigurationShouldSucceed() throws Exception { + + mockGmond.setMinimumExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + mockGmond.whenAnyExchangeReceived(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Ganglia_message gangliaMessage = exchange.getIn().getBody(Ganglia_message.class); + assertNotNull("The gmond mock should only receive a non-null ganglia message", gangliaMessage); + assertEquals(DEFAULT_METRIC_NAME, gangliaMessage.gmetric.name); + assertEquals(DEFAULT_TYPE.getGangliaType(), gangliaMessage.gmetric.type); + assertEquals(DEFAULT_SLOPE.getGangliaSlope(), gangliaMessage.gmetric.slope); + assertEquals(DEFAULT_UNITS, gangliaMessage.gmetric.units); + assertEquals(DEFAULT_TMAX, gangliaMessage.gmetric.tmax); + assertEquals(DEFAULT_DMAX, gangliaMessage.gmetric.dmax); + assertEquals("28.0", gangliaMessage.gmetric.value); + } + }); + + template.sendBody(getTestUri(), "28.0"); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendMessageHeadersShouldOverrideDefaultConfiguration() throws Exception { + + mockGmond.setMinimumExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + mockGmond.whenAnyExchangeReceived(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Ganglia_message gangliaMessage = exchange.getIn().getBody(Ganglia_message.class); + assertNotNull("The gmond mock should only receive a non-null ganglia message", gangliaMessage); + assertEquals("depth", gangliaMessage.gmetric.name); + assertEquals("float", gangliaMessage.gmetric.type); + assertEquals(2, gangliaMessage.gmetric.slope); + assertEquals("cm", gangliaMessage.gmetric.units); + assertEquals(100, gangliaMessage.gmetric.tmax); + assertEquals(10, gangliaMessage.gmetric.dmax); + assertEquals("-3.0", gangliaMessage.gmetric.value); + } + }); + + Map<String, Object> headers = new HashMap<>(); + headers.put(GROUP_NAME, "sea-mesure"); + headers.put(METRIC_NAME, "depth"); + headers.put(METRIC_TYPE, FLOAT); + headers.put(METRIC_SLOPE, NEGATIVE); + headers.put(METRIC_UNITS, "cm"); + headers.put(METRIC_TMAX, 100); + headers.put(METRIC_DMAX, 10); + template.sendBodyAndHeaders(getTestUri(), -3.0f, headers); + + mockGmond.assertIsSatisfied(); + } + + @Override + public JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("protocolV30Decoder", new ProtocolV30Decoder()); + return jndi; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("netty4:udp://localhost:" + getTestPort() + "/?decoders=#protocolV30Decoder").to(mockGmond); + } + }; + } + + @Sharable + public static class ProtocolV30Decoder extends MessageToMessageDecoder<DatagramPacket> { + @Override + protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws OncRpcException, IOException { + byte[] bytes = new byte[packet.content().readableBytes()]; + packet.content().readBytes(bytes); + + // Unmarshall the incoming datagram + XdrBufferDecodingStream xbds = new XdrBufferDecodingStream(bytes); + Ganglia_message outMsg = new Ganglia_message(); + xbds.beginDecoding(); + outMsg.xdrDecode(xbds); + xbds.endDecoding(); + out.add(outMsg); + } + } +} diff --git a/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java new file mode 100644 index 0000000..0319dbb --- /dev/null +++ b/components/camel-ganglia/src/test/java/org/apache/camel/component/ganglia/GangliaProtocolV31CamelTest.java @@ -0,0 +1,259 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.ganglia; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import info.ganglia.gmetric4j.xdr.v31x.Ganglia_metadata_msg; +import info.ganglia.gmetric4j.xdr.v31x.Ganglia_value_msg; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.socket.DatagramPacket; +import io.netty.handler.codec.MessageToMessageDecoder; + +import org.acplt.oncrpc.OncRpcException; +import org.acplt.oncrpc.XdrAble; +import org.acplt.oncrpc.XdrBufferDecodingStream; +import org.apache.camel.CamelExecutionException; +import org.apache.camel.EndpointInject; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.ResolveEndpointFailedException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static info.ganglia.gmetric4j.gmetric.GMetricSlope.NEGATIVE; +import static info.ganglia.gmetric4j.gmetric.GMetricType.FLOAT; + +import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetadata_full; +import static info.ganglia.gmetric4j.xdr.v31x.Ganglia_msg_formats.gmetric_string; + +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_DMAX; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_METRIC_NAME; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_SLOPE; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_TMAX; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_TYPE; +import static org.apache.camel.component.ganglia.GangliaConfiguration.DEFAULT_UNITS; + +import static org.apache.camel.component.ganglia.GangliaConstants.GROUP_NAME; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_DMAX; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_NAME; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_SLOPE; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TMAX; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_TYPE; +import static org.apache.camel.component.ganglia.GangliaConstants.METRIC_UNITS; + +/** + * {@code GangliaProtocolV31CamelTest} is not shipped with an embedded gmond + * agent. The gmond agent is mocked with the help of camel-netty4 codecs and a + * mock endpoint. As underlying UDP packets are not guaranteed to be delivered, + * loose assertions are performed. + */ +public class GangliaProtocolV31CamelTest extends CamelGangliaTestSupport { + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @EndpointInject(uri = "mock:gmond") + private MockEndpoint mockGmond; + + private String getTestUri() { + return "ganglia:localhost:" + getTestPort() + "?mode=UNICAST"; + } + + @Test + public void sendDefaultConfigurationShouldSucceed() throws Exception { + + mockGmond.setMinimumExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + mockGmond.whenAnyExchangeReceived(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Ganglia_metadata_msg metadataMessage = exchange.getIn().getBody(Ganglia_metadata_msg.class); + if (metadataMessage != null) { + assertEquals(DEFAULT_METRIC_NAME, metadataMessage.gfull.metric.name); + assertEquals(DEFAULT_TYPE.getGangliaType(), metadataMessage.gfull.metric.type); + assertEquals(DEFAULT_SLOPE.getGangliaSlope(), metadataMessage.gfull.metric.slope); + assertEquals(DEFAULT_UNITS, metadataMessage.gfull.metric.units); + assertEquals(DEFAULT_TMAX, metadataMessage.gfull.metric.tmax); + assertEquals(DEFAULT_DMAX, metadataMessage.gfull.metric.dmax); + } else { + Ganglia_value_msg valueMessage = exchange.getIn().getBody(Ganglia_value_msg.class); + if (valueMessage != null) { + assertEquals("28.0", valueMessage.gstr.str); + assertEquals("%s", valueMessage.gstr.fmt); + } else { + fail("The gmond mock should only receive non-null metadata or value messages"); + } + } + } + }); + + template.sendBody(getTestUri(), "28.0"); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendMessageHeadersShouldOverrideDefaultConfiguration() throws Exception { + + mockGmond.setMinimumExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + mockGmond.whenAnyExchangeReceived(new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + Ganglia_metadata_msg metadataMessage = exchange.getIn().getBody(Ganglia_metadata_msg.class); + if (metadataMessage != null) { + assertEquals("depth", metadataMessage.gfull.metric.name); + assertEquals(FLOAT.getGangliaType(), metadataMessage.gfull.metric.type); + assertEquals(NEGATIVE.getGangliaSlope(), metadataMessage.gfull.metric.slope); + assertEquals("cm", metadataMessage.gfull.metric.units); + assertEquals(100, metadataMessage.gfull.metric.tmax); + assertEquals(10, metadataMessage.gfull.metric.dmax); + } else { + Ganglia_value_msg valueMessage = exchange.getIn().getBody(Ganglia_value_msg.class); + if (valueMessage != null) { + assertEquals("-3.0", valueMessage.gstr.str); + assertEquals("%s", valueMessage.gstr.fmt); + } else { + fail("The gmond mock should only receive non-null metadata or value messages"); + } + } + } + }); + + Map<String, Object> headers = new HashMap<>(); + headers.put(GROUP_NAME, "sea-mesure"); + headers.put(METRIC_NAME, "depth"); + headers.put(METRIC_TYPE, FLOAT); + headers.put(METRIC_SLOPE, NEGATIVE); + headers.put(METRIC_UNITS, "cm"); + headers.put(METRIC_TMAX, 100); + headers.put(METRIC_DMAX, 10); + template.sendBodyAndHeaders(getTestUri(), -3.0f, headers); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendWrongMetricTypeShouldThrow() throws Exception { + thrown.expect(CamelExecutionException.class); + mockGmond.setExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + + template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TYPE, "NotAGMetricType"); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendWrongMetricSlopeShouldThrow() throws Exception { + thrown.expect(CamelExecutionException.class); + mockGmond.setExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + + template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_SLOPE, "NotAGMetricSlope"); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendWrongMetricTMaxShouldThrow() throws Exception { + thrown.expect(CamelExecutionException.class); + mockGmond.setExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + + template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_TMAX, new Object()); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendWrongMetricDMaxShouldThrow() throws Exception { + thrown.expect(CamelExecutionException.class); + mockGmond.setExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + + template.sendBodyAndHeader(getTestUri(), "28.0", METRIC_DMAX, new Object()); + + mockGmond.assertIsSatisfied(); + } + + @Test + public void sendWithWrongTypeShouldThrow() throws Exception { + thrown.expect(ResolveEndpointFailedException.class); + mockGmond.setExpectedMessageCount(0); + mockGmond.setAssertPeriod(100L); + + template.sendBody(getTestUri() + "&type=wrong", ""); + + mockGmond.assertIsSatisfied(); + } + + @Override + public JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("protocolV31Decoder", new ProtocolV31Decoder()); + return jndi; + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("netty4:udp://localhost:" + getTestPort() + "/?decoders=#protocolV31Decoder").to(mockGmond); + } + }; + } + + @Sharable + public static class ProtocolV31Decoder extends MessageToMessageDecoder<DatagramPacket> { + @Override + protected void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out) throws OncRpcException, IOException { + byte[] bytes = new byte[packet.content().readableBytes()]; + packet.content().readBytes(bytes); + + // Determine what kind of object the datagram is handling + XdrBufferDecodingStream xbds = new XdrBufferDecodingStream(bytes); + xbds.beginDecoding(); + int id = xbds.xdrDecodeInt() & 0xbf; + xbds.endDecoding(); + XdrAble outMsg = null; + if (id == gmetadata_full) { + outMsg = new Ganglia_metadata_msg(); + } else if (id == gmetric_string) { + outMsg = new Ganglia_value_msg(); + } else { + fail("During those tests, the gmond mock should only receive metadata or string messages"); + } + + // Unmarshall the incoming datagram + xbds = new XdrBufferDecodingStream(bytes); + xbds.beginDecoding(); + outMsg.xdrDecode(xbds); + xbds.endDecoding(); + out.add(outMsg); + } + } +} -- To stop receiving notification emails like this one, please contact aldettin...@apache.org.