Search in sources :

Example 6 with Calculator

use of org.apache.openejb.itest.failover.ejb.Calculator in project tomee by apache.

the class LegacyServerTest method test.

@Test
public void test() throws Exception {
    final String jv = System.getProperty("java.version");
    assumeTrue(jv.startsWith("1.7") || jv.startsWith("1.8"));
    // To run in an IDE, uncomment and update this line
    // System.setProperty("version", OpenEjbVersion.get().getVersion());
    System.setProperty("openejb.client.connection.strategy", "roundrobin");
    logger.info("Retrieving standalone server: " + Repository.guessVersion("org.apache.openejb", "openejb-standalone") + " - This may take a while...");
    final File zip = Repository.getArtifact("org.apache.openejb", "openejb-standalone", "zip");
    final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");
    final File dir = Files.tmpdir();
    final StandaloneServer root;
    {
        final String name = "root";
        final File home = new File(dir, name);
        Files.mkdir(home);
        Zips.unzip(zip, home, true);
        root = new StandaloneServer(home, home);
        root.killOnExit();
        root.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
        root.ignoreOut();
        root.setProperty("name", name);
        root.setProperty("openejb.extract.configuration", "false");
        final StandaloneServer.ServerService multipoint = root.getServerService("multipoint");
        multipoint.setBind("localhost");
        multipoint.setPort(getNextAvailablePort());
        multipoint.setDisabled(false);
        multipoint.set("discoveryName", name);
        logger.info("Starting Root server");
        // Wait for it to start before continuing, otherwise test may fail in slower machines.
        root.start(1, TimeUnit.MINUTES);
    }
    final Services services = new Services();
    Client.addEventObserver(services);
    final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();
    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);
        final StandaloneServer.ServerService 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(CLIENT_DELAY, TimeUnit.SECONDS, new CalculatorCallable(bean), 500);
        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
    }
    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(String.format("Starting %s server", name));
        server.start(1, TimeUnit.MINUTES);
        services.add(serverURI);
        logger.info("Waiting for updated list");
        services.assertServices(CLIENT_DELAY, TimeUnit.SECONDS, new CalculatorCallable(bean), 500);
        logger.info("Asserting balance");
        assertBalance(bean, services.get().size());
    }
}
Also used : HashMap(java.util.HashMap) Properties(java.util.Properties) URI(java.net.URI) InitialContext(javax.naming.InitialContext) StandaloneServer(org.apache.openejb.server.control.StandaloneServer) Calculator(org.apache.openejb.itest.failover.ejb.Calculator) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) EJBException(javax.ejb.EJBException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with Calculator

use of org.apache.openejb.itest.failover.ejb.Calculator in project tomee by apache.

the class ReconnectDelayCaseInsensitiveTest method test.

@Test
public void test() throws Exception {
    // To run in an IDE, uncomment and update this line
    System.setProperty("version", OpenEjbVersion.get().getVersion());
    final Duration reconnectDelay = new Duration("1 second");
    final File zip = Repository.getArtifact("org.apache.tomee", "openejb-standalone", "zip");
    final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");
    final File dir = Files.tmpdir();
    System.setProperty("openejb.client.requestretry", "true");
    final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();
    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.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
        server.getProperties().put("name", name);
        server.getProperties().put("openejb.extract.configuration", "false");
        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.setDisabled(false);
        ejbd.setBind("0.0.0.0");
        ejbd.setPort(getAvailablePort());
        ejbd.setThreads(5);
        ejbd.set("discoveryHost", "localhost");
        ejbd.set("discovery", "ejb:ejbd://{discoveryHost}:{port}/" + name);
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        multipoint.setBind("0.0.0.0");
        multipoint.setPort(getAvailablePort());
        multipoint.setDisabled(false);
        multipoint.set("discoveryHost", "localhost");
        multipoint.set("discoveryName", name);
        multipoint.set("reconnectDelay", reconnectDelay.toString());
        servers.put(name, server);
    }
    final StandaloneServer red = servers.get("red");
    // Set all the initialServers to point to RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        final StandaloneServer server = entry.getValue();
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        final String value = "lOcAlHosT:" + red.getServerService(MULTIPOINT).getPort() + ",locALHost:" + multipoint.getPort();
        multipoint.set("initialServers", value);
    }
    // Start all the servers except RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        if (entry.getKey().equals("red"))
            continue;
        entry.getValue().start(1, TimeUnit.MINUTES);
    }
    // Verify Failover is not yet functional
    {
        // RED was never started so BLUE never found any peers
        // Lets invoke BLUE then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer blue = servers.get("blue");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke BLUE a few times
        invoke(bean, 10, "blue");
        // Kill BLUE
        blue.kill();
        // Invocations should now fail (and not failover)
        try {
            bean.name();
            Assert.fail("Server should be down and failover not hooked up");
        } catch (final Exception e) {
        // pass
        }
    }
    // Now we start RED
    red.start(1, TimeUnit.MINUTES);
    // Wait for the reconnectDelay so GREEN can find RED
    Thread.sleep((long) (reconnectDelay.getTime(TimeUnit.MILLISECONDS) * 1.5));
    // Verify Failover is now functional
    {
        // RED was never started so GREEN never found any peers
        // Lets invoke GREEN then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer green = servers.get("green");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + green.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke GREEN a few times
        invoke(bean, 10, "green");
        // Kill GREEN
        green.kill();
        // Invocations should now failover to RED
        invoke(bean, 10, "red");
    }
}
Also used : HashMap(java.util.HashMap) Duration(org.apache.openejb.util.Duration) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StandaloneServer(org.apache.openejb.server.control.StandaloneServer) Calculator(org.apache.openejb.itest.failover.ejb.Calculator) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 8 with Calculator

use of org.apache.openejb.itest.failover.ejb.Calculator in project tomee by apache.

the class ReconnectDelayListSelfTest method test.

@Test
public void test() throws Exception {
    // To run in an IDE, uncomment and update this line
    System.setProperty("version", OpenEjbVersion.get().getVersion());
    final Duration reconnectDelay = new Duration("1 second");
    final File zip = Repository.getArtifact("org.apache.tomee", "openejb-standalone", "zip");
    final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");
    final File dir = Files.tmpdir();
    System.setProperty("openejb.client.requestretry", "true");
    final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();
    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.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
        server.getProperties().put("name", name);
        server.getProperties().put("openejb.extract.configuration", "false");
        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.setDisabled(false);
        ejbd.setBind("0.0.0.0");
        ejbd.setPort(getAvailablePort());
        ejbd.setThreads(5);
        ejbd.set("discoveryHost", "localhost");
        ejbd.set("discovery", "ejb:ejbd://{discoveryHost}:{port}/" + name);
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        multipoint.setBind("0.0.0.0");
        multipoint.setPort(getAvailablePort());
        multipoint.setDisabled(false);
        multipoint.set("discoveryHost", "localhost");
        multipoint.set("discoveryName", name);
        multipoint.set("reconnectDelay", reconnectDelay.toString());
        servers.put(name, server);
    }
    final StandaloneServer red = servers.get("red");
    // Set all the initialServers to point to RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        final StandaloneServer server = entry.getValue();
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        final String value = "localhost:" + red.getServerService(MULTIPOINT).getPort() + ",localhost:" + multipoint.getPort();
        multipoint.set("initialServers", value);
    }
    // Start all the servers except RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        if (entry.getKey().equals("red"))
            continue;
        entry.getValue().start(1, TimeUnit.MINUTES);
    }
    // Verify Failover is not yet functional
    {
        // RED was never started so BLUE never found any peers
        // Lets invoke BLUE then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer blue = servers.get("blue");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke BLUE a few times
        invoke(bean, 10, "blue");
        // Kill BLUE
        blue.kill();
        // Invocations should now fail (and not failover)
        try {
            bean.name();
            Assert.fail("Server should be down and failover not hooked up");
        } catch (final Exception e) {
        // pass
        }
    }
    // Now we start RED
    red.start(1, TimeUnit.MINUTES);
    // Wait for the reconnectDelay so GREEN can find RED
    Thread.sleep((long) (reconnectDelay.getTime(TimeUnit.MILLISECONDS) * 1.5));
    // Verify Failover is now functional
    {
        // RED was never started so GREEN never found any peers
        // Lets invoke GREEN then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer green = servers.get("green");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + green.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke GREEN a few times
        invoke(bean, 10, "green");
        // Kill GREEN
        green.kill();
        // Invocations should now failover to RED
        invoke(bean, 10, "red");
    }
}
Also used : HashMap(java.util.HashMap) Duration(org.apache.openejb.util.Duration) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StandaloneServer(org.apache.openejb.server.control.StandaloneServer) Calculator(org.apache.openejb.itest.failover.ejb.Calculator) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with Calculator

use of org.apache.openejb.itest.failover.ejb.Calculator in project tomee by apache.

the class ReconnectDelayTest method test.

@Test
public void test() throws Exception {
    // To run in an IDE, uncomment and update this line
    System.setProperty("version", OpenEjbVersion.get().getVersion());
    final Duration reconnectDelay = new Duration("1 second");
    final File zip = Repository.getArtifact("org.apache.tomee", "openejb-standalone", "zip");
    final File app = Repository.getArtifact("org.apache.openejb.itests", "failover-ejb", "jar");
    final File dir = Files.tmpdir();
    System.setProperty("openejb.client.requestretry", "true");
    final Map<String, StandaloneServer> servers = new HashMap<String, StandaloneServer>();
    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.getJvmOpts().add("-Dopenejb.classloader.forced-load=org.apache.openejb");
        server.getProperties().put("name", name);
        server.getProperties().put("openejb.extract.configuration", "false");
        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.setDisabled(false);
        ejbd.setBind("0.0.0.0");
        ejbd.setPort(getAvailablePort());
        ejbd.setThreads(5);
        ejbd.set("discoveryHost", "localhost");
        ejbd.set("discovery", "ejb:ejbd://{discoveryHost}:{port}/" + name);
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        multipoint.setBind("0.0.0.0");
        multipoint.setPort(getAvailablePort());
        multipoint.setDisabled(false);
        multipoint.set("discoveryHost", "localhost");
        multipoint.set("discoveryName", name);
        multipoint.set("reconnectDelay", reconnectDelay.toString());
        servers.put(name, server);
    }
    final StandaloneServer red = servers.get("red");
    // Set all the initialServers to point to RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        final StandaloneServer server = entry.getValue();
        final StandaloneServer.ServerService multipoint = server.getServerService(MULTIPOINT);
        multipoint.set("initialServers", "localhost:" + red.getServerService(MULTIPOINT).getPort());
    }
    // Start all the servers except RED
    for (final Map.Entry<String, StandaloneServer> entry : servers.entrySet()) {
        if (entry.getKey().equals("red"))
            continue;
        entry.getValue().start(1, TimeUnit.MINUTES);
    }
    // Verify Failover is not yet functional
    {
        // RED was never started so BLUE never found any peers
        // Lets invoke BLUE then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer blue = servers.get("blue");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + blue.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke BLUE a few times
        invoke(bean, 10, "blue");
        // Kill BLUE
        blue.kill();
        // Invocations should now fail (and not failover)
        try {
            bean.name();
            Assert.fail("Server should be down and failover not hooked up");
        } catch (final Exception e) {
        // pass
        }
    }
    // Now we start RED
    red.start(1, TimeUnit.MINUTES);
    // Wait for the reconnectDelay so GREEN can find RED
    Thread.sleep((long) (reconnectDelay.getTime(TimeUnit.MILLISECONDS) * 1.5));
    // Verify Failover is now functional
    {
        // RED was never started so GREEN never found any peers
        // Lets invoke GREEN then shut it down and verify we have
        // no other peers to invoke
        final StandaloneServer green = servers.get("green");
        final Properties environment = new Properties();
        environment.put(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
        environment.put(Context.PROVIDER_URL, "ejbd://localhost:" + green.getServerService("ejbd").getPort());
        final InitialContext context = new InitialContext(environment);
        final Calculator bean = (Calculator) context.lookup("CalculatorBeanRemote");
        // Invoke GREEN a few times
        invoke(bean, 10, "green");
        // Kill GREEN
        green.kill();
        // Invocations should now failover to RED
        invoke(bean, 10, "red");
    }
}
Also used : HashMap(java.util.HashMap) Duration(org.apache.openejb.util.Duration) Properties(java.util.Properties) InitialContext(javax.naming.InitialContext) StandaloneServer(org.apache.openejb.server.control.StandaloneServer) Calculator(org.apache.openejb.itest.failover.ejb.Calculator) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Calculator

use of org.apache.openejb.itest.failover.ejb.Calculator 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
    }
}
Also used : Properties(java.util.Properties) URI(java.net.URI) InitialContext(javax.naming.InitialContext) StandaloneServer(org.apache.openejb.server.control.StandaloneServer) Calculator(org.apache.openejb.itest.failover.ejb.Calculator) RemoteInitialContextFactory(org.apache.openejb.client.RemoteInitialContextFactory) EJBException(javax.ejb.EJBException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)10 InitialContext (javax.naming.InitialContext)10 Calculator (org.apache.openejb.itest.failover.ejb.Calculator)10 File (java.io.File)9 StandaloneServer (org.apache.openejb.server.control.StandaloneServer)9 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 Map (java.util.Map)7 RemoteInitialContextFactory (org.apache.openejb.client.RemoteInitialContextFactory)7 EJBException (javax.ejb.EJBException)6 URI (java.net.URI)4 Duration (org.apache.openejb.util.Duration)3 ArrayList (java.util.ArrayList)1 Ignore (org.junit.Ignore)1