use of org.apache.openejb.server.control.StandaloneServer in project tomee by apache.
the class LegacyClientTest method test.
@Test
public void test() throws Exception {
// To run in an IDE, uncomment and update this line
// System.setProperty("version", OpenEjbVersion.get().getVersion());
System.setProperty("openejb.client.connection.strategy", "roundrobin");
StandaloneServer.ServerService multipoint = root.getServerService("multipoint");
multipoint.setBind("localhost");
multipoint.setPort(getNextAvailablePort());
multipoint.setDisabled(false);
multipoint.set("discoveryName", rootname);
logger.info("Starting Root server");
root.start();
final Services services = new Services();
Client.addEventObserver(services);
for (final String name : new String[] { "red", "green", "blue" }) {
final File home = new File(dir, name);
Files.mkdir(home);
Zips.unzip(zip, home, true);
final StandaloneServer server = new StandaloneServer(home, home);
server.killOnExit();
server.ignoreOut();
server.setProperty("name", name);
server.setProperty("openejb.extract.configuration", "false");
server.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
IO.copy(app, Files.path(home, "apps", "itest.jar"));
IO.copy(IO.read("<openejb><Deployments dir=\"apps/\"/></openejb>"), Files.path(home, "conf", "openejb.xml"));
final StandaloneServer.ServerService ejbd = server.getServerService("ejbd");
ejbd.setBind("localhost");
ejbd.setDisabled(false);
ejbd.setPort(getNextAvailablePort());
ejbd.setThreads(5);
final URI uri = URI.create(String.format("ejbd://%s:%s/%s", ejbd.getBind(), ejbd.getPort(), name));
ejbd.set("discovery", "ejb:" + uri);
services.add(uri);
server.getContext().set(URI.class, uri);
multipoint = server.getServerService("multipoint");
multipoint.setPort(getNextAvailablePort());
multipoint.setDisabled(false);
multipoint.set("discoveryName", name);
multipoint.set("initialServers", "localhost:" + root.getServerService("multipoint").getPort());
servers.put(name, server);
logger.info(String.format("Starting %s server", name));
server.start(1, TimeUnit.MINUTES);
}
System.setProperty("openejb.client.requestretry", "true");
System.setProperty("openejb.client.connection.strategy", "random");
logger.info("Beginning Test");
final Properties environment = new Properties();
environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + servers.values().iterator().next().getServerService("ejbd").getPort() + "/provider");
final InitialContext context = new InitialContext(environment);
final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
final String name = entry.getKey();
final StandaloneServer server = entry.getValue();
final URI serverURI = server.getContext().get(URI.class);
logger.info("Waiting for updated list");
services.assertServices(2, TimeUnit.MINUTES, new CalculatorCallable(bean), 1500);
logger.info("Asserting balance");
assertBalance(bean, services.get().size());
logger.info("Shutting down " + name);
server.kill();
services.remove(serverURI);
}
logger.info("All Servers Shutdown");
try {
logger.info("Making one last request, expecting complete failover");
final String name = bean.name();
Assert.fail("Server should be destroyed: " + name);
} catch (final EJBException e) {
logger.info(String.format("Pass. Request resulted in %s: %s", e.getCause().getClass().getSimpleName(), e.getMessage()));
// good
}
}
use of org.apache.openejb.server.control.StandaloneServer in project tomee by apache.
the class LegacyClientTest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
logger.info("Retrieving standalone server: " + Repository.guessVersion("org.apache.tomee", "openejb-standalone") + " - This may take a while...");
zip = Repository.getArtifact("org.apache.tomee", "openejb-standalone", "zip");
app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");
final File roothome = new File(dir, rootname);
Files.mkdir(roothome);
Zips.unzip(zip, roothome, true);
root = new StandaloneServer(roothome, roothome);
root.killOnExit();
root.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
root.ignoreOut();
root.setProperty("name", rootname);
root.setProperty("openejb.extract.configuration", "false");
}
Aggregations