mirror of https://github.com/apache/activemq.git
AMQ-7189: ensure messages with defauled durable field are internally classed non-persistent by the 'native' transformer
This commit is contained in:
parent
30abc45f62
commit
aff9413cdb
|
@ -91,6 +91,8 @@ public abstract class InboundTransformer {
|
||||||
|
|
||||||
if (header.getDurable() != null) {
|
if (header.getDurable() != null) {
|
||||||
jms.setPersistent(header.getDurable().booleanValue());
|
jms.setPersistent(header.getDurable().booleanValue());
|
||||||
|
} else {
|
||||||
|
jms.setPersistent(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (header.getPriority() != null) {
|
if (header.getPriority() != null) {
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* 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.transport.amqp.interop;
|
||||||
|
|
||||||
|
public class AmqpSendReceiveNativeTest extends AmqpSendReceiveTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getAmqpTransformer() {
|
||||||
|
return "native";
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import javax.jms.DeliveryMode;
|
||||||
import javax.jms.Queue;
|
import javax.jms.Queue;
|
||||||
import javax.jms.Topic;
|
import javax.jms.Topic;
|
||||||
|
|
||||||
|
@ -46,6 +47,10 @@ import org.apache.activemq.transport.amqp.client.AmqpReceiver;
|
||||||
import org.apache.activemq.transport.amqp.client.AmqpSender;
|
import org.apache.activemq.transport.amqp.client.AmqpSender;
|
||||||
import org.apache.activemq.transport.amqp.client.AmqpSession;
|
import org.apache.activemq.transport.amqp.client.AmqpSession;
|
||||||
import org.apache.activemq.util.Wait;
|
import org.apache.activemq.util.Wait;
|
||||||
|
import org.apache.qpid.proton.amqp.UnsignedByte;
|
||||||
|
import org.apache.qpid.proton.amqp.messaging.AmqpValue;
|
||||||
|
import org.apache.qpid.proton.amqp.messaging.Header;
|
||||||
|
import org.apache.qpid.proton.message.Message;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -496,6 +501,20 @@ public class AmqpSendReceiveTest extends AmqpClientTestSupport {
|
||||||
|
|
||||||
@Test(timeout = 60000)
|
@Test(timeout = 60000)
|
||||||
public void testMessageWithNoHeaderNotMarkedDurable() throws Exception {
|
public void testMessageWithNoHeaderNotMarkedDurable() throws Exception {
|
||||||
|
doMessageNotMarkedDurableTestImpl(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testMessageWithHeaderAndDefaultedNonDurableNotMarkedDurable() throws Exception {
|
||||||
|
doMessageNotMarkedDurableTestImpl(true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(timeout = 60000)
|
||||||
|
public void testMessageWithHeaderAndMarkedNonDurableNotMarkedDurable() throws Exception {
|
||||||
|
doMessageNotMarkedDurableTestImpl(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doMessageNotMarkedDurableTestImpl(boolean sendHeaderWithPriority, boolean explicitSetNonDurable) throws Exception {
|
||||||
AmqpClient client = createAmqpClient();
|
AmqpClient client = createAmqpClient();
|
||||||
AmqpConnection connection = trackConnection(client.connect());
|
AmqpConnection connection = trackConnection(client.connect());
|
||||||
AmqpSession session = connection.createSession();
|
AmqpSession session = connection.createSession();
|
||||||
|
@ -503,16 +522,39 @@ public class AmqpSendReceiveTest extends AmqpClientTestSupport {
|
||||||
AmqpSender sender = session.createSender("queue://" + getTestName());
|
AmqpSender sender = session.createSender("queue://" + getTestName());
|
||||||
AmqpReceiver receiver1 = session.createReceiver("queue://" + getTestName());
|
AmqpReceiver receiver1 = session.createReceiver("queue://" + getTestName());
|
||||||
|
|
||||||
// Create default message that should be sent as non-durable
|
Message protonMessage = Message.Factory.create();
|
||||||
AmqpMessage message1 = new AmqpMessage();
|
protonMessage.setMessageId("ID:Message:1");
|
||||||
message1.setText("Test-Message -> non-durable");
|
protonMessage.setBody(new AmqpValue("Test-Message -> non-durable"));
|
||||||
message1.setMessageId("ID:Message:1");
|
if(sendHeaderWithPriority) {
|
||||||
|
Header header = new Header();
|
||||||
|
if(explicitSetNonDurable) {
|
||||||
|
header.setDurable(false);
|
||||||
|
}
|
||||||
|
header.setPriority(UnsignedByte.valueOf((byte) 5));
|
||||||
|
|
||||||
|
protonMessage.setHeader(header);
|
||||||
|
} else {
|
||||||
|
assertNull("Should not have a header", protonMessage.getHeader());
|
||||||
|
}
|
||||||
|
|
||||||
|
AmqpMessage message1 = new AmqpMessage(protonMessage);
|
||||||
|
|
||||||
sender.send(message1);
|
sender.send(message1);
|
||||||
|
|
||||||
|
final QueueViewMBean queueView = getProxyToQueue(getTestName());
|
||||||
|
assertNotNull(queueView);
|
||||||
|
|
||||||
|
assertEquals(1, queueView.getQueueSize());
|
||||||
|
|
||||||
|
List<javax.jms.Message> messages = (List<javax.jms.Message>) queueView.browseMessages();
|
||||||
|
assertEquals(1, messages.size());
|
||||||
|
javax.jms.Message queueMessage = messages.get(0);
|
||||||
|
assertEquals("Queued message should not be persistent", DeliveryMode.NON_PERSISTENT, queueMessage.getJMSDeliveryMode());
|
||||||
|
|
||||||
receiver1.flow(1);
|
receiver1.flow(1);
|
||||||
AmqpMessage message2 = receiver1.receive(50, TimeUnit.SECONDS);
|
AmqpMessage message2 = receiver1.receive(50, TimeUnit.SECONDS);
|
||||||
assertNotNull("Should have read a message", message2);
|
assertNotNull("Should have read a message", message2);
|
||||||
assertFalse("Second message sent should not be durable", message2.isDurable());
|
assertFalse("Received message should not be durable", message2.isDurable());
|
||||||
message2.accept();
|
message2.accept();
|
||||||
|
|
||||||
sender.close();
|
sender.close();
|
||||||
|
|
Loading…
Reference in New Issue