jbertram commented on code in PR #5079: URL: https://github.com/apache/activemq-artemis/pull/5079#discussion_r1678353444
########## artemis-server/src/test/java/org/apache/activemq/artemis/core/config/DivertConfigurationEncodingTest.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.activemq.artemis.core.config; + +import org.apache.activemq.artemis.api.core.ActiveMQBuffer; +import org.apache.activemq.artemis.api.core.ActiveMQBuffers; +import org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DivertConfigurationEncodingTest { + + @Test + public void testStoreDivertConfigurationWithTransformerNoProperties() { + DivertConfiguration configuration = new DivertConfiguration(); + configuration.setName("myDivertName"); + configuration.setAddress("myDivertAddress"); + configuration.setForwardingAddress("myDivertForwardingAddress"); + configuration.setFilterString("foo='foo'"); + configuration.setRoutingName("myDivertRoutingName"); + configuration.setExclusive(false); + configuration.setRoutingType(ComponentConfigurationRoutingType.ANYCAST); + TransformerConfiguration myDivertTransformer = new TransformerConfiguration("myDivertTransformer"); + myDivertTransformer.getProperties().put("foo", "foo"); + configuration.setTransformerConfiguration(myDivertTransformer); + + int encodeSize = configuration.getEncodeSize(); + ActiveMQBuffer data = ActiveMQBuffers.fixedBuffer(encodeSize); + configuration.encode(data); + assertEquals(encodeSize, data.writerIndex()); Review Comment: > The bug here was apparently that the value of getEncodeSize() was wrong. That was _most_ of the bug, but not all. There was also a bug in the actual encoding (which used `writeString` instead of `writeNullableString`). > For a comprehensive encoder test I'd expect an assertion on the exact actual value for given inputs to check it is as expected, but there still isnt such an assertion. The test does, in fact, make an assertion on the actual value in question (i.e. the data in the buffer) to ensure it matches the calculated encoded size. Are you suggesting the test essentially re-implement `o.a.a.a.c.c.DivertConfiguration#getEncodeSize` and compare that with the value that the "real" implementation returns? > All the tests do is verify the number of bytes written equals that value returned, which it always should, but that doesnt actually check the value was correct to expectations. I'm not following. If the code just tested something which "always should" be the case then it would never fail. However, the test does fail if you remove the fix(es). To be clear, the test is comparing the _calculated_ encoding size with the _actual_ encoded size of the data to ensure they are the same. > Similarly with the actual encoded bytes, they are not directly asserted, only indirectly verified by using the decoder. I'm not clear on how to "directly" assert the values of the bytes without essentially re-implementing the decoder or using static values which themselves are generated from existing code. Do you have any specific suggestions on how to do this? FWIW, my goal for this PR was not to provide an exhaustive set of tests for divert encoding/decoding. I simply wanted to fix and verify the specific use-case from ARTEMIS-4910. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact