Created
August 14, 2009 20:25
-
-
Save dblevins/168083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF 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.apache.openejb; | |
import junit.framework.Assert; | |
import org.apache.openejb.config.RemoteServer; | |
import org.apache.openejb.client.ConnectionManager; | |
import org.apache.openejb.client.Connection; | |
import org.junit.Test; | |
import javax.naming.Context; | |
import javax.naming.InitialContext; | |
import javax.naming.NameClassPair; | |
import javax.naming.NamingEnumeration; | |
import javax.naming.NamingException; | |
import java.util.Properties; | |
import java.net.URI; | |
public class DeployUndeploy { | |
private Context ctx; | |
public boolean init() { | |
try { | |
System.setProperty("openejb.client.connectionpool.size", "1"); | |
Properties props = new Properties(); | |
props.put(Context.INITIAL_CONTEXT_FACTORY, | |
"org.apache.openejb.client.RemoteInitialContextFactory"); | |
props.put(Context.PROVIDER_URL, "ejbd://127.0.0.1:4201"); | |
ctx = new InitialContext(props); | |
return true; | |
} catch (NamingException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
} | |
public boolean list() { | |
try { | |
NamingEnumeration<NameClassPair> list = ctx.list(""); | |
while (list.hasMore()) { | |
System.out.println("name: " + list.next().getName()); | |
} | |
return true; | |
} catch (NamingException e) { | |
e.printStackTrace(); | |
return false; | |
} | |
} | |
@Test | |
public void deployundeploy() throws Exception { | |
System.setProperty("openejb.home", "/tmp/openejb-3.1.1"); | |
String[] param = new String[1]; | |
param[0] = "start"; | |
RemoteServer.main(param); | |
DeployUndeploy deployUndeploy = new DeployUndeploy(); | |
deployUndeploy.init(); | |
deployUndeploy.list(); | |
param = new String[1]; | |
param[0] = "stop"; | |
RemoteServer.main(param); | |
// Forcebly remove the only connection in our pool (size=1) | |
Connection connection = ConnectionManager.getConnection(URI.create("ejbd://127.0.0.1:4201")); | |
connection.discard(); | |
try { | |
Thread.sleep(5000); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
Assert.fail(); | |
} | |
param = new String[1]; | |
param[0] = "start"; | |
RemoteServer.main(param); | |
try { | |
deployUndeploy.init(); | |
deployUndeploy.list(); | |
} catch (RuntimeException e) { | |
e.printStackTrace(); | |
Assert.fail(); | |
} finally { | |
param = new String[1]; | |
param[0] = "stop"; | |
RemoteServer.main(param); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment