Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 1 | /* |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved. |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 3 | * |
| 4 | * This program and the accompanying materials are made available under the |
| 5 | * terms of the Eclipse Public License v. 2.0, which is available at |
| 6 | * http://www.eclipse.org/legal/epl-2.0. |
| 7 | * |
| 8 | * This Source Code may also be made available under the following Secondary |
| 9 | * Licenses when the conditions for such availability set forth in the |
| 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, |
| 11 | * version 2 with the GNU Classpath Exception, which is available at |
| 12 | * https://www.gnu.org/software/classpath/license.html. |
| 13 | * |
| 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 |
| 15 | */ |
| 16 | |
| 17 | package com.acme; |
| 18 | |
| 19 | import admin.AdminBaseDevTest; |
| 20 | import com.sun.ejte.ccl.reporter.SimpleReporterAdapter; |
| 21 | |
| 22 | import java.io.*; |
| 23 | import java.net.*; |
| 24 | import java.util.*; |
| 25 | |
| 26 | /* |
| 27 | * CLI Dev test |
| 28 | * @author mvatkina |
| 29 | */ |
| 30 | public class Client extends ClientBase { |
| 31 | |
| 32 | public static void main(String[] args) { |
| 33 | |
| 34 | if ("prepare".equals(args[0])) { |
| 35 | (new Client()).prepare(args[1]); |
| 36 | } else if ("deploy".equals(args[0])) { |
| 37 | (new Client()).deploy(args[1]); |
| 38 | } else if ("undeploy".equals(args[0])) { |
| 39 | (new Client()).undeploy(args[1]); |
| 40 | } else if ("insert_xa_data".equals(args[0])) { |
| 41 | (new Client()).insert_xa_data(args[1], args[2], args[3]); |
| 42 | } else { |
| 43 | (new Client()).process(args); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | protected String getTestDescription() { |
| 49 | return "Unit test for transaction recovery with MDBs"; |
| 50 | } |
| 51 | |
| 52 | public void prepare(String enable_delegate) { |
| 53 | try { |
| 54 | asadmin("create-cluster", CLUSTER_NAME); |
| 55 | asadmin("set", "configs.config." + CLUSTER_NAME + "-config.transaction-service.property.db-logging-resource=" + NONTX_RESOURCE); |
| 56 | if (Boolean.valueOf(enable_delegate)) { |
| 57 | asadmin("set", "configs.config." + CLUSTER_NAME + "-config.transaction-service.property.delegated-recovery=true"); |
| 58 | } |
| 59 | asadmin("create-local-instance", "--cluster", CLUSTER_NAME, INSTANCE1_NAME); |
| 60 | asadmin("create-local-instance", "--cluster", CLUSTER_NAME, INSTANCE2_NAME); |
| 61 | System.out.println("Creating JMS resources"); |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame^] | 62 | asadmin("create-jms-resource", "--target", CLUSTER_NAME, "--restype", "jakarta.jms.QueueConnectionFactory", "jms/ejb_mdb_QCF"); |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 63 | asadmin("create-jmsdest", "--target", CLUSTER_NAME, "--desttype", "ejb_mdb_Queue"); |
Gaurav Gupta | 3655507 | 2020-03-26 14:10:23 +0530 | [diff] [blame^] | 64 | asadmin("create-jms-resource", "--target", CLUSTER_NAME, "--restype", "jakarta.jms.Queue", "--property", "imqDestinationName=ejb_mdb_Queue", "jms/ejb_mdb_Queue"); |
Vinay Vishal | 5717147 | 2018-09-18 20:22:00 +0530 | [diff] [blame] | 65 | System.out.println("Finished creating JMS resources"); |
| 66 | |
| 67 | if (Boolean.getBoolean("enableShoalLogger")) { |
| 68 | asadmin("set-log-levels", "ShoalLogger=FINER"); |
| 69 | asadmin("set-log-levels", "--target", CLUSTER_NAME, "ShoalLogger=FINER"); |
| 70 | } |
| 71 | asadmin("create-resource-ref", "--target", CLUSTER_NAME, XA_RESOURCE); |
| 72 | asadmin("create-resource-ref", "--target", CLUSTER_NAME, NONTX_RESOURCE); |
| 73 | asadmin("create-resource-ref", "--target", CLUSTER_NAME, "jms/ejb_mdb_QCF"); |
| 74 | asadmin("create-resource-ref", "--target", CLUSTER_NAME, "jms/ejb_mdb_Queue"); |
| 75 | asadmin("start-cluster", CLUSTER_NAME); |
| 76 | System.out.println("Started cluster."); |
| 77 | |
| 78 | } catch (Exception e) { |
| 79 | e.printStackTrace(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public void deploy(String path) { |
| 84 | try { |
| 85 | asadmin("deploy", "--target", CLUSTER_NAME, path); |
| 86 | System.out.println("Deployed " + path); |
| 87 | } catch (Exception e) { |
| 88 | e.printStackTrace(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public void insert_xa_data(String appname, String instance, String sendMsg) { |
| 93 | if (Boolean.valueOf(sendMsg)) |
| 94 | execute(appname, instance, "TestServlet?2", "true"); |
| 95 | else |
| 96 | execute(appname, instance, "TestServlet", "true"); |
| 97 | } |
| 98 | |
| 99 | public void verify(String appname, String instance, String operation, String servlet) { |
| 100 | stat.addDescription("transaction-ee-" + operation); |
| 101 | |
| 102 | boolean res = execute(appname, instance, servlet, "RESULT:6"); |
| 103 | |
| 104 | stat.addStatus("transaction-ee-dblogs-mdb" + operation, ((res)? stat.PASS : stat.FAIL)); |
| 105 | stat.printSummary("transaction-ee-dblogs-mdb" + operation); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void clean(String name) { |
| 110 | try { |
| 111 | asadmin("delete-jms-resource", "--target", CLUSTER_NAME, "jms/ejb_mdb_QCF"); |
| 112 | asadmin("delete-jms-resource", "--target", CLUSTER_NAME, "jms/ejb_mdb_Queue"); |
| 113 | asadmin("delete-jmsdest", "--target", CLUSTER_NAME, "ejb_mdb_Queue"); |
| 114 | System.out.println("Deleted JMS resources."); |
| 115 | |
| 116 | super.clean(null); |
| 117 | } catch (Exception e) { |
| 118 | e.printStackTrace(); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | public void undeploy(String name) { |
| 123 | try { |
| 124 | asadmin("undeploy", "--target", CLUSTER_NAME, name); |
| 125 | System.out.println("Undeployed " + name); |
| 126 | } catch (Exception e) { |
| 127 | e.printStackTrace(); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | } |