Commit 0719d206 authored by Andre Freyssinet's avatar Andre Freyssinet
Browse files

Adds tests for issue in String length computing (Joram#314380).

parent 79aac4b0
......@@ -507,7 +507,10 @@
<antcall target="noreg.test61"/>
<antcall target="noreg.test62"/>
<antcall target="noreg.test63"/>
<antcall target="noreg.test64"/>
<antcall target="noreg.test64"/>
<antcall target="noreg.encodingTest1"/>
<antcall target="noreg.encodingTest2"/>
<antcall target="noreg.encodingTest3"/>
</target>
<target name="tests.xa"
......@@ -5010,6 +5013,39 @@
</antcall>
</target>
<target name="noreg.encodingTest1" depends="init.a3props,compile"
description=" --> .">
<antcall target="test.run" inheritAll="true">
<param name="className" value="joram.noreg.EncodingTest1"/>
<param name="testid" value="noreg.encodingTest1"/>
<param name="jndiconf" value="noreg/jndi.properties"/>
<param name="a3conf" value="noreg/a3servers1.xml"/>
<param name="jvmargs" value="-Dfile.encoding=UTF-8"/>
</antcall>
</target>
<target name="noreg.encodingTest2" depends="init.a3props,compile"
description=" --> .">
<antcall target="test.run" inheritAll="true">
<param name="className" value="joram.noreg.EncodingTest2"/>
<param name="testid" value="noreg.encodingTest2"/>
<param name="jndiconf" value="noreg/jndi.properties"/>
<param name="a3conf" value="noreg/a3servers1.xml"/>
<param name="jvmargs" value="-Dfile.encoding=UTF-8"/>
</antcall>
</target>
<target name="noreg.encodingTest3" depends="init.a3props,compile"
description=" --> .">
<antcall target="test.run" inheritAll="true">
<param name="className" value="joram.noreg.EncodingTest3"/>
<param name="testid" value="noreg.encodingTest3"/>
<param name="jndiconf" value="noreg/jndi.properties"/>
<param name="a3conf" value="noreg/a3servers1.xml"/>
<param name="jvmargs" value="-Dfile.encoding=UTF-8"/>
</antcall>
</target>
<!-- end noreg -->
<!-- test with bug -->
......
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2022 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.noreg;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.DeliveryMode;
import jakarta.jms.ExceptionListener;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import java.nio.charset.Charset;
import org.ow2.joram.jakarta.jms.Queue;
import org.ow2.joram.jakarta.jms.admin.AdminModule;
import org.ow2.joram.jakarta.jms.admin.User;
import org.ow2.joram.jakarta.jms.tcp.TcpConnectionFactory;
import framework.TestCase;
/**
* Test charset issues.
*/
public class EncodingTest1 extends TestCase implements ExceptionListener {
public static void main(String[] args) {
new EncodingTest1().run();
}
public void run() {
try {
startAgentServer((short) 0, new String[] {
// "-Dfile.encoding=UTF-8"
});
Thread.sleep(1000);
Charset charset = Charset.defaultCharset();
System.out.println(charset.name() + " = " + charset.newEncoder().maxBytesPerChar());
charset = Charset.forName("UTF-8");
System.out.println(charset.name() + " = " + charset.newEncoder().maxBytesPerChar());
charset = Charset.forName("UTF-16");
System.out.println(charset.name() + " = " + charset.newEncoder().maxBytesPerChar());
charset = Charset.forName("ASCII");
System.out.println(charset.name() + " = " + charset.newEncoder().maxBytesPerChar());
charset = Charset.forName("ISO-8859-15");
System.out.println(charset.name() + " = " + charset.newEncoder().maxBytesPerChar());
// Create an administration connection on server #0
ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
((TcpConnectionFactory) cf).getParameters().cnxPendingTimer = 5000;
((TcpConnectionFactory) cf).getParameters().connectingTimer = 30;
AdminModule.connect(cf, "root", "root");
Queue queue = Queue.create(0, "queue");
queue.setFreeReading();
queue.setFreeWriting();
// Create the anonymous user needed for test
User.create("anonymous", "anonymous");
AdminModule.disconnect();
Thread.sleep(1000);
Connection cnx = cf.createConnection("anonymous", "anonymous");
cnx.setClientID("ITSME");
cnx.setExceptionListener(this);
Session session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = session.createConsumer(queue);
MessageProducer prod = session.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
cnx.start();
String utf8Content = "abcdef \uF93D\uF936\uF949\uF942";
System.out.println("utf8Content: " + utf8Content);
System.out.println("utf8Content: " + utf8Content.length() + "/" + utf8Content.getBytes().length + "/" + utf8Content.getBytes("UTF-8").length);
TextMessage sent = session.createTextMessage(utf8Content);
sent.setStringProperty("content", utf8Content);
sent.setJMSCorrelationID(utf8Content);
prod.send(sent);
TextMessage recv = (TextMessage) cons.receive(1000L);
System.out.println("Body: " + recv.getText());
assertTrue("Body is not ok", utf8Content.equals(recv.getText()));
String prop = recv.getStringProperty("content");
System.out.println("Property: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("Property is not ok", utf8Content.equals(prop));
prop = recv.getJMSCorrelationID();
System.out.println("JMSCorrelationID: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("JMSCorrelationID is not ok", utf8Content.equals(recv.getJMSCorrelationID()));
System.out.println("JMS OK");
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
killAgentServer((short) 0);
endTest();
}
}
@Override
public void onException(JMSException e) {
System.out.println("JMS NOK -> " + e.getMessage());
// this.exc = e;
// e.printStackTrace();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2022 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.noreg;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.DeliveryMode;
import jakarta.jms.ExceptionListener;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import org.ow2.joram.jakarta.jms.Queue;
import org.ow2.joram.jakarta.jms.admin.AdminModule;
import org.ow2.joram.jakarta.jms.admin.User;
import org.ow2.joram.jakarta.jms.local.LocalConnectionFactory;
import org.ow2.joram.jakarta.jms.tcp.TcpConnectionFactory;
import fr.dyade.aaa.agent.AgentServer;
import framework.TestCase;
/**
* Test charset issues.
*/
public class EncodingTest2 extends TestCase implements ExceptionListener {
public static void main(String[] args) {
new EncodingTest2().run();
}
Queue queue;
public void run() {
try {
AgentServer.init((short) 0, "s0", null);
AgentServer.start();
Thread.sleep(1000L);
// Create an administration connection on server #0
ConnectionFactory cf1 = LocalConnectionFactory.create();
((LocalConnectionFactory) cf1).getParameters().cnxPendingTimer = 5000;
((LocalConnectionFactory) cf1).getParameters().connectingTimer = 30;
AdminModule.connect(cf1, "root", "root");
queue = Queue.create(0, "queue");
queue.setFreeReading();
queue.setFreeWriting();
// Create the anonymous user needed for test
User.create("anonymous", "anonymous");
AdminModule.disconnect();
test(cf1);
// Create an administration connection on server #0
ConnectionFactory cf2 = TcpConnectionFactory.create("localhost", 16010);
((TcpConnectionFactory) cf2).getParameters().cnxPendingTimer = 5000;
((TcpConnectionFactory) cf2).getParameters().connectingTimer = 30;
test(cf2);
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
killAgentServer((short) 0);
endTest();
}
}
private void test(ConnectionFactory cf) throws Exception {
Connection cnx = cf.createConnection("anonymous", "anonymous");
cnx.setExceptionListener(this);
Session session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = session.createConsumer(queue);
MessageProducer prod = session.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
cnx.start();
String utf8Content = new String("abcdef \uF93D\uF936\uF949\uF942");
System.out.println("utf8Content: " + utf8Content);
System.out.println("utf8Content: " + utf8Content.length() + "/" + utf8Content.getBytes().length + "/" + utf8Content.getBytes("UTF-8").length);
TextMessage sent = session.createTextMessage(utf8Content);
sent.setStringProperty("content", utf8Content);
sent.setJMSCorrelationID(utf8Content);
prod.send(sent);
TextMessage recv = (TextMessage) cons.receive(1000L);
System.out.println("Body: " + recv.getText());
assertTrue("Body is not ok", utf8Content.equals(recv.getText()));
String prop = recv.getStringProperty("content");
System.out.println("Property: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("Property is not ok", utf8Content.equals(prop));
prop = recv.getJMSCorrelationID();
System.out.println("JMSCorrelationID: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("JMSCorrelationID is not ok", utf8Content.equals(recv.getJMSCorrelationID()));
}
@Override
public void onException(JMSException e) {
System.out.println("JMS NOK -> " + e.getMessage());
// this.exc = e;
// e.printStackTrace();
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2022 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent Distributed Technologies
* Contributor(s):
*/
package joram.noreg;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.DeliveryMode;
import org.objectweb.joram.client.jms.Queue;
import org.objectweb.joram.client.jms.admin.AdminModule;
import org.objectweb.joram.client.jms.admin.User;
import org.objectweb.joram.client.jms.tcp.TcpConnectionFactory;
import framework.TestCase;
/**
* Test charset issues.
*/
public class EncodingTest3 extends TestCase {
public static void main(String[] args) {
new EncodingTest3().run();
}
public void run() {
try {
startAgentServer((short) 0, new String[] {});
Thread.sleep(1000);
// Create an administration connection on server #0
ConnectionFactory cf = TcpConnectionFactory.create("localhost", 16010);
((TcpConnectionFactory) cf).getParameters().cnxPendingTimer = 5000;
((TcpConnectionFactory) cf).getParameters().connectingTimer = 30;
AdminModule.connect(cf, "root", "root");
Queue queue = Queue.create(0, "queue");
queue.setFreeReading();
queue.setFreeWriting();
// Create the anonymous user needed for test
User.create("anonymous", "anonymous");
AdminModule.disconnect();
Thread.sleep(1000);
Connection cnx = cf.createConnection("anonymous", "anonymous");
Session session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer prod = session.createProducer(queue);
prod.setDeliveryMode(DeliveryMode.PERSISTENT);
cnx.start();
String utf8Content = "abcdef � \uF93D\uF936\uF949\uF942";
System.out.println("utf8Content: " + utf8Content);
System.out.println("utf8Content: " + utf8Content.length() + "/" + utf8Content.getBytes().length + "/" + utf8Content.getBytes("UTF-8").length);
TextMessage sent = session.createTextMessage(utf8Content);
sent.setStringProperty("content", utf8Content);
sent.setJMSCorrelationID(utf8Content);
prod.send(sent);
cnx.close();
stopAgentServer((short) 0);
System.out.println("Server stopped.");
Thread.sleep(1000);
startAgentServer((short) 0, new String[] {
"-Dfile.encoding=UTF-8"
});
System.out.println("Server started.");
Thread.sleep(1000);
cnx = cf.createConnection("anonymous", "anonymous");
session = cnx.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer cons = session.createConsumer(queue);
cnx.start();
TextMessage recv = (TextMessage) cons.receive(1000L);
System.out.println("Body: " + recv.getText());
assertTrue("Body is not ok", utf8Content.equals(recv.getText()));
String prop = recv.getStringProperty("content");
System.out.println("Property: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("Property is not ok", utf8Content.equals(prop));
prop = recv.getJMSCorrelationID();
System.out.println("JMSCorrelationID: " + prop + " -> " + prop.length() + "/" + prop.getBytes().length + "/" + prop.getBytes("UTF-8").length);
assertTrue("JMSCorrelationID is not ok", utf8Content.equals(recv.getJMSCorrelationID()));
System.out.println("JMS OK");
} catch (Throwable exc) {
exc.printStackTrace();
error(exc);
} finally {
killAgentServer((short) 0);
endTest();
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment