blob: 70e6244f5763a81f3d7130bddc5361251f4fbf8b [file] [log] [blame]
/*
* Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package admin;
import com.sun.appserv.test.BaseDevTest;
/*
import com.sun.messaging.AdminConnectionConfiguration;
import com.sun.messaging.AdminConnectionFactory;
*
*/
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.util.HashMap;
import java.util.Map;
/*
* @author Satish
*/
public class ConfigureJmsClusterTest extends AdminBaseDevTest {
public static final String CLUSTER_NAME = "cluster1";
public static final String INSTANCE1_NAME = "instance1";
public static final String INSTANCE2_NAME = "instance2";
public static final String STANDALONE_INSTANCE_NAME = "instance3";
public static void main(String[] args) {
new ConfigureJmsClusterTest().runTests();
}
@Override
protected String getTestDescription() {
return "Unit test for dynamically changing master broker";
}
@Override
public void cleanup() {
try {
asadmin("stop-local-instance", STANDALONE_INSTANCE_NAME);
// asadmin("delete-local-instance", STANDALONE_INSTANCE_NAME);
asadmin("stop-local-instance", INSTANCE1_NAME);
asadmin("stop-local-instance", INSTANCE2_NAME);
asadmin("stop-cluster", CLUSTER_NAME);
asadmin("delete-local-instance", INSTANCE1_NAME);
asadmin("delete-local-instance", INSTANCE2_NAME);
asadmin("delete-cluster", CLUSTER_NAME);
asadmin("stop-database");
} catch (Exception e) {
e.printStackTrace();
}
}
public void runTests() {
startDomain();
asadmin("create-cluster", CLUSTER_NAME);
configurejmscluster();
asadmin("create-local-instance", "--cluster", CLUSTER_NAME,
/*"--node", "localhost",*/ "--systemproperties",
"HTTP_LISTENER_PORT=18080:HTTP_SSL_LISTENER_PORT=18181:IIOP_SSL_LISTENER_PORT=13800:IIOP_LISTENER_PORT=13700:JMX_SYSTEM_CONNECTOR_PORT=17676:IIOP_SSL_MUTUALAUTH_PORT=13801:JMS_PROVIDER_PORT=18686:ASADMIN_LISTENER_PORT=14848",
INSTANCE1_NAME);
asadmin("create-local-instance", "--cluster", CLUSTER_NAME,
/*"--node", "localhost",*/ "--systemproperties",
"HTTP_LISTENER_PORT=28080:HTTP_SSL_LISTENER_PORT=28181:IIOP_SSL_LISTENER_PORT=23800:IIOP_LISTENER_PORT=23700:JMX_SYSTEM_CONNECTOR_PORT=27676:IIOP_SSL_MUTUALAUTH_PORT=23801:JMS_PROVIDER_PORT=28686:ASADMIN_LISTENER_PORT=24848",
INSTANCE2_NAME);
asadmin("start-cluster", CLUSTER_NAME);
//checkMasterBroker("18686");
asadmin("stop-local-instance", INSTANCE1_NAME);
createJmsDest("testqueue2");
listJmsDest("testqueue2");
configureJmsClusterWithoutForce();
configureJmsClusterWithForce();
asadmin("stop-cluster", CLUSTER_NAME);
asadmin ("start-cluster", CLUSTER_NAME);
try{
Thread.sleep(5000);
}catch(Exception e)
{
e.printStackTrace();
}
//checkMasterBroker("18686");
createJmsDest("anothertestqueue");
listJmsDest("anothertestqueue");
cleanup();
stopDomain();
stat.printSummary();
}
private void configurejmscluster(){
String testName = "RunConfigureJmsCluster";
asadmin("start-database");
AsadminReturn result = asadminWithOutput("configure-jms-cluster", "--clustertype", "conventional",
"--messagestoretype", "file", "--configstoretype", "shareddb", "--dbvendor", "derby", "--dbuser", "dbuser",
"--dburl", "jdbc:derby://localhost:1527/testdb/retreiveMessagesFromServerOnGetMessage=true;create=true", "cluster1");
reportResultStatus(testName, result);
}
private void checkMasterBroker(String jmsport){
String testName = "checkMasterBroker";
Object output = jmxCall(jmsport, "com.sun.messaging.jms.server:type=Cluster,subtype=Monitor", "MasterBrokerInfo");
AsadminReturn result = new AsadminReturn();//asadminWithOutput(DELETE_CONNECTOR_RESOURCE,TARGET_OPTION, target, RESOURCE_NAME);
result.returnValue = result != null;
if(output != null) result.out = (String) (((CompositeDataSupport) output).get("imq.cluster.nomasterbroker"));
result.err="";
System.out.println("MasterBroker " + result.out);
//result.out=
reportResultStatus(testName, result);
reportExpectedResult(testName, result, "true");
}
private void createJmsDest(String destname){
String testName = "CreateJMSDest";
AsadminReturn result = asadminWithOutput("create-jmsdest", "--target", CLUSTER_NAME, "--desttype", "queue", destname);
reportResultStatus(testName, result);
}
private void listJmsDest(String destname){
String testName = "ListJMSDest";
AsadminReturn result = asadminWithOutput("list-jmsdest", CLUSTER_NAME);
reportResultStatus(testName, result);
reportExpectedResult(testName, result, destname);
}
private void configureJmsClusterWithoutForce(){
asadmin("start-local-instance", INSTANCE1_NAME);
String testName = "RunConfigureJmsClusterWithoutForce";
AsadminReturn result = asadminWithOutput("configure-jms-cluster", "--clustertype", "conventional",
"--messagestoretype", "file", "--configstoretype", "masterbroker", "cluster1");
reportFailureResultStatus(testName, result);
}
private void configureJmsClusterWithForce(){
String testName = "RunConfigureJmsClusterWithForce";
AsadminReturn result = asadminWithOutput("configure-jms-cluster", "--clustertype", "conventional",
"--messagestoretype", "file", "--configstoretype", "masterbroker", "--force", "cluster1");
reportResultStatus(testName, result);
}
public Object jmxCall(String jmsProviderPort, String objectName, String attrName){
/*
* Commented out because building this code depends on having GlassFish already downloaded.
* The admin devtest must build without having GlassFish present.
try{
AdminConnectionFactory acf = new AdminConnectionFactory();
acf.setProperty(AdminConnectionConfiguration.imqAddress, "localhost:" + jmsProviderPort);
JMXConnector connector = acf.createConnection("admin","admin");
MBeanServerConnection mbsc = connector.getMBeanServerConnection();
System.out.println("connected to target server");
ObjectName objName
= new ObjectName(objectName);
Object attrvalue = mbsc.getAttribute(objName, attrName);
connector.close();
return attrvalue;
}catch(Exception ex){
ex.printStackTrace();
}
*/
return null;
}
private void reportFailureResultStatus(String testName, AsadminReturn result) {
report(testName, ! result.returnValue);
report(testName, ! result.err.isEmpty());
}
private void reportResultStatus(String testName, AsadminReturn result) {
report(testName, result.returnValue);
report(testName, result.err.isEmpty());
}
private void reportExpectedFailureResult(String testName, AsadminReturn result, String... expected) {
for (String token : expected) {
report(testName, result.err.contains(token));
}
}
private void reportExpectedResult(String testName, AsadminReturn result, String... expected) {
for (String token : expected) {
report(testName, result.out.contains(token));
}
}
private void reportUnexpectedResult(String testName, AsadminReturn result, String... unexpected) {
for (String token : unexpected) {
report(testName, !result.out.contains(token));
}
}
}