Skip to content

Commit

Permalink
Use a single createServer(configuration) method
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco Borges committed Nov 18, 2011
1 parent 8ca96e4 commit 7858a6a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ protected void createConfigs() throws Exception
ClusterConnectionConfiguration cccLive = new ClusterConnectionConfiguration("cluster1", "jms", backupConnector.getName(), -1, false, false, 1, 1,
staticConnectors, false);
backupConfig.getClusterConfigurations().add(cccLive);
backupServer = createBackupServer();
backupServer = createServer(backupConfig);

liveConfig = super.createDefaultConfig();
liveConfig.getAcceptorConfigurations().clear();
Expand All @@ -267,7 +267,7 @@ protected void createConfigs() throws Exception
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
liveConfig.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
liveServer = createLiveServer();
liveServer = createServer(liveConfig);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected void createConfigs() throws Exception
staticConnectors, false);
backupConfig.getClusterConfigurations().add(cccLive);
backupConfig.setAllowAutoFailBack(false);
backupServer = createBackupServer();
backupServer = createServer(backupConfig);

liveConfig = super.createDefaultConfig();
liveConfig.getAcceptorConfigurations().clear();
Expand All @@ -178,7 +178,7 @@ protected void createConfigs() throws Exception
liveConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
liveConfig.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
liveConfig.setAllowAutoFailBack(false);
liveServer = createLiveServer();
liveServer = createServer(liveConfig);
}

@Override
Expand Down Expand Up @@ -246,6 +246,7 @@ private ClientSession sendAndConsume(final ClientSessionFactory sf, final boolea
* @param message
* @throws Exception
*/
@Override
protected void setBody(final int i, final ClientMessage message) throws Exception
{
message.getBodyBuffer().writeString("message" + i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,10 @@ protected void setUp() throws Exception
}
}

protected TestableServer createLiveServer()
protected TestableServer createServer(Configuration config)
{
return new SameProcessHornetQServer(createInVMFailoverServer(true, liveConfig, nodeManager, 1));
}

protected TestableServer createBackupServer()
{
return new SameProcessHornetQServer(createInVMFailoverServer(true, backupConfig, nodeManager, 2));
return new SameProcessHornetQServer(
createInVMFailoverServer(true, config, nodeManager, config.isBackup() ? 2 : 1));
}

/**
Expand Down Expand Up @@ -189,7 +185,7 @@ protected void createConfigs() throws Exception
backupConfig.getConnectorConfigurations().put(backupConnector.getName(), backupConnector);
ReplicatedBackupUtils.createClusterConnectionConf(backupConfig, backupConnector.getName(),
liveConnector.getName());
backupServer = createBackupServer();
backupServer = createServer(backupConfig);

liveConfig = super.createDefaultConfig();
liveConfig.getAcceptorConfigurations().clear();
Expand All @@ -199,11 +195,13 @@ protected void createConfigs() throws Exception
liveConfig.setClustered(true);
ReplicatedBackupUtils.createClusterConnectionConf(liveConfig, liveConnector.getName());
liveConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
liveServer = createLiveServer();
liveServer = createServer(liveConfig);
}

protected void createReplicatedConfigs() throws Exception
protected void createReplicatedConfigs()
{
nodeManager = new InVMNodeManager();

final TransportConfiguration liveConnector = getConnectorTransportConfiguration(true);
final TransportConfiguration backupConnector = getConnectorTransportConfiguration(false);
final TransportConfiguration backupAcceptor = getAcceptorTransportConfiguration(false);
Expand All @@ -215,18 +213,18 @@ protected void createReplicatedConfigs() throws Exception
ReplicatedBackupUtils.configureReplicationPair(backupConfig, backupConnector, backupAcceptor, liveConfig,
liveConnector);

backupConfig.setBindingsDirectory(backupConfig.getBindingsDirectory() + "_backup");
backupConfig.setJournalDirectory(backupConfig.getJournalDirectory() + "_backup");
backupConfig.setPagingDirectory(backupConfig.getPagingDirectory() + "_backup");
backupConfig.setLargeMessagesDirectory(backupConfig.getLargeMessagesDirectory() + "_backup");
final String sufix = "_backup";
backupConfig.setBindingsDirectory(backupConfig.getBindingsDirectory() + sufix);
backupConfig.setJournalDirectory(backupConfig.getJournalDirectory() + sufix);
backupConfig.setPagingDirectory(backupConfig.getPagingDirectory() + sufix);
backupConfig.setLargeMessagesDirectory(backupConfig.getLargeMessagesDirectory() + sufix);
backupConfig.setSecurityEnabled(false);

backupServer = createBackupServer();
backupServer = createServer(backupConfig);
liveConfig.getAcceptorConfigurations().clear();
liveConfig.getAcceptorConfigurations().add(getAcceptorTransportConfiguration(true));


liveServer = createLiveServer();
liveServer = createServer(liveConfig);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.hornetq.tests.integration.cluster.failover;

import org.hornetq.core.config.Configuration;
import org.hornetq.tests.integration.cluster.util.SameProcessHornetQServer;
import org.hornetq.tests.integration.cluster.util.TestableServer;

Expand All @@ -24,40 +25,15 @@
public class NettyReplicatedFailoverTest extends NettyFailoverTest
{

// Constants -----------------------------------------------------

// Attributes ----------------------------------------------------

// Static --------------------------------------------------------

// Constructors --------------------------------------------------

// Public --------------------------------------------------------

// Package protected ---------------------------------------------

// Protected -----------------------------------------------------

@Override
protected TestableServer createLiveServer()
protected TestableServer createServer(Configuration config)
{
return new SameProcessHornetQServer(createServer(true, liveConfig));
}

@Override
protected TestableServer createBackupServer()
{
return new SameProcessHornetQServer(createServer(true, backupConfig));
return new SameProcessHornetQServer(createServer(true, config));
}

@Override
protected void createConfigs() throws Exception
{
createReplicatedConfigs();
}

// Private -------------------------------------------------------

// Inner classes -------------------------------------------------

}
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,9 @@ protected HornetQServer createServer(final boolean realFiles, final Configuratio
}

@Override
protected TestableServer createBackupServer()
protected TestableServer createServer(Configuration config)
{
return new SameProcessHornetQServer(createServer(true, backupConfig));
}

@Override
protected TestableServer createLiveServer()
{
return new SameProcessHornetQServer(createServer(true, liveConfig));
return new SameProcessHornetQServer(createServer(true, config));
}

// Private -------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,22 @@ protected void tearDown() throws Exception
}
catch (Exception e)
{
e.printStackTrace();
e.printStackTrace();
}
}
}

@Override
protected TestableServer createLiveServer()
protected TestableServer createServer(Configuration config)
{
if (config.isBackup())
{
return new SameProcessHornetQServer(HornetQServers.newHornetQServer(config));
}
return new RemoteProcessHornetQServer(SharedLiveServerConfiguration.class.getName());
}

@Override
protected TestableServer createBackupServer()
{
return new SameProcessHornetQServer(HornetQServers.newHornetQServer(backupConfig));
}

protected TransportConfiguration getConnectorTransportConfiguration(final boolean live) {
Map<String, Object> params = null;
if (live)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package org.hornetq.tests.integration.cluster.failover;

import org.hornetq.tests.integration.cluster.util.SameProcessHornetQServer;
import org.hornetq.tests.integration.cluster.util.TestableServer;

/**
* A ReplicatedAsynchronousFailoverTest
Expand All @@ -23,19 +21,6 @@
*/
public class ReplicatedAsynchronousFailoverTest extends AsynchronousFailoverTest
{

@Override
protected TestableServer createLiveServer()
{
return new SameProcessHornetQServer(createInVMFailoverServer(true, liveConfig, nodeManager, 1));
}

@Override
protected TestableServer createBackupServer()
{
return new SameProcessHornetQServer(createInVMFailoverServer(true, backupConfig, nodeManager, 2));
}

@Override
protected void createConfigs() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.hornetq.api.core.client.ClientSession;
import org.hornetq.api.core.client.ClientSessionFactory;
import org.hornetq.core.config.ClusterConnectionConfiguration;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.security.Role;
import org.hornetq.core.server.impl.InVMNodeManager;
import org.hornetq.spi.core.security.HornetQSecurityManager;
Expand Down Expand Up @@ -67,6 +66,7 @@ protected ClientSession createSession(ClientSessionFactory sf,
ackBatchSize);
}

@Override
protected ClientSession createSession(ClientSessionFactory sf,
boolean autoCommitSends,
boolean autoCommitAcks,
Expand All @@ -76,16 +76,19 @@ protected ClientSession createSession(ClientSessionFactory sf,
.isPreAcknowledge(), ackBatchSize);
}

@Override
protected ClientSession createSession(ClientSessionFactory sf, boolean autoCommitSends, boolean autoCommitAcks) throws Exception
{
return createSession(sf, autoCommitSends, autoCommitAcks, sf.getServerLocator().getAckBatchSize());
}

@Override
protected ClientSession createSession(ClientSessionFactory sf) throws Exception
{
return createSession(sf, true, true, sf.getServerLocator().getAckBatchSize());
}

@Override
protected ClientSession createSession(ClientSessionFactory sf,
boolean xa,
boolean autoCommitSends,
Expand All @@ -97,6 +100,7 @@ protected ClientSession createSession(ClientSessionFactory sf,
/**
* @throws Exception
*/
@Override
protected void createConfigs() throws Exception
{
nodeManager = new InVMNodeManager();
Expand Down Expand Up @@ -125,7 +129,7 @@ protected void createConfigs() throws Exception
staticConnectors,
false);
backupConfig.getClusterConfigurations().add(cccLive);
backupServer = createBackupServer();
backupServer = createServer(backupConfig);

HornetQSecurityManager securityManager = installSecurity(backupServer);

Expand All @@ -150,11 +154,12 @@ protected void createConfigs() throws Exception
false);
liveConfig.getClusterConfigurations().add(ccc0);
liveConfig.getConnectorConfigurations().put(liveConnector.getName(), liveConnector);
liveServer = createLiveServer();
liveServer = createServer(liveConfig);

installSecurity(liveServer);
}

@Override
protected void beforeRestart(TestableServer server)
{
installSecurity(server);
Expand Down

0 comments on commit 7858a6a

Please sign in to comment.