Skip to content

Commit

Permalink
HORNETQ-884 - adding test-case
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Bertram committed May 9, 2012
1 parent 0a2d3b6 commit 69bf9b7
Showing 1 changed file with 120 additions and 0 deletions.
@@ -0,0 +1,120 @@
/*
* Copyright 2009 Red Hat, Inc.
* Red Hat 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.hornetq.tests.integration.client;

import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.client.ServerLocator;
import org.hornetq.api.jms.HornetQJMSClient;
import org.hornetq.api.jms.JMSFactoryType;
import org.hornetq.core.client.impl.ServerLocatorImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.logging.Logger;
import org.hornetq.core.server.HornetQServer;
import org.hornetq.jms.client.HornetQConnectionFactory;
import org.hornetq.tests.util.ServiceTestBase;

import javax.jms.Connection;
import javax.jms.Session;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class ServerLocatorSerializationTest extends ServiceTestBase
{
private HornetQServer server;
private static final Logger log = Logger.getLogger(ServerLocatorSerializationTest.class);

@Override
protected void setUp() throws Exception
{
super.setUp();
Configuration configuration = createDefaultConfig(isNetty());
server = createServer(false, configuration);
server.start();
}

@Override
protected void tearDown() throws Exception
{
server.stop();
super.tearDown();
}

public void testLocatorSerialization() throws Exception
{
log.info("Starting Netty locator");
ServerLocator locator = HornetQClient.createServerLocatorWithoutHA(createTransportConfiguration(isNetty(), false, generateParams(0, isNetty())));

ClientSessionFactory csf = locator.createSessionFactory();
ClientSession session = csf.createSession(false, false);
session.close();
csf.close();

log.info("Serializing locator");
ServerLocatorImpl locatorImpl = (ServerLocatorImpl) locator;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(locatorImpl);

log.info("De-serializing locator");
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bis);
locatorImpl = (ServerLocatorImpl) in.readObject();

csf = locator.createSessionFactory();
session = csf.createSession(false, false);
session.close();
csf.close();

locator.close();
locatorImpl.close();
}

public void testConnectionFactorySerialization() throws Exception
{
log.info("Starting connection factory");
HornetQConnectionFactory cf = HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration("org.hornetq.core.remoting.impl.netty.NettyConnectorFactory"));

Connection connection = cf.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.close();
connection.close();

log.info("Serializing connection factory");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(cf);

log.info("De-serializing connection factory");
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bis);
cf = (HornetQConnectionFactory) in.readObject();

connection = cf.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.close();
connection.close();

cf.close();
}

public boolean isNetty()
{
return true;
}
}

0 comments on commit 69bf9b7

Please sign in to comment.