View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.protocol.test;
22  
23  import goldengate.common.logging.GgInternalLogger;
24  import goldengate.common.logging.GgInternalLoggerFactory;
25  import goldengate.common.logging.GgSlf4JLoggerFactory;
26  
27  import java.util.concurrent.ExecutorService;
28  import java.util.concurrent.Executors;
29  
30  import openr66.client.AbstractBusinessRequest;
31  import openr66.configuration.FileBasedConfiguration;
32  import openr66.database.data.DbHostAuth;
33  import openr66.protocol.configuration.Configuration;
34  import openr66.protocol.localhandler.packet.BusinessRequestPacket;
35  import openr66.protocol.networkhandler.NetworkTransaction;
36  import openr66.protocol.utils.R66Future;
37  
38  import org.jboss.netty.logging.InternalLoggerFactory;
39  
40  /**
41   * Test class for internal Business test
42   * @author Frederic Bregier
43   *
44   */
45  public class TestBusinessRequest extends AbstractBusinessRequest {
46      /**
47       * Internal Logger
48       */
49      private static GgInternalLogger logger;
50  
51      public TestBusinessRequest(NetworkTransaction networkTransaction,
52              R66Future future, String remoteHost, BusinessRequestPacket packet) {
53          super(TestBusinessRequest.class, future, remoteHost, networkTransaction, packet);
54      }
55  
56      public static void main(String[] args) {
57          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(
58                  null));
59          if (logger == null) {
60              logger = GgInternalLoggerFactory.getLogger(TestBusinessRequest.class);
61          }
62          if (args.length < 1) {
63              logger
64                      .error("Needs at least the configuration file as first argument");
65              return;
66          }
67          if (! FileBasedConfiguration
68                  .setClientConfigurationFromXml(Configuration.configuration, args[0])) {
69              logger
70                      .error("Needs a correct configuration file as first argument");
71              return;
72          }
73          Configuration.configuration.pipelineInit();
74  
75          final NetworkTransaction networkTransaction = new NetworkTransaction();
76          DbHostAuth host = Configuration.configuration.HOST_AUTH;
77          ExecutorService executorService = Executors.newCachedThreadPool();
78          int nb = 100;
79  
80          R66Future[] arrayFuture = new R66Future[nb];
81          logger.info("Start Test of Transaction");
82          long time1 = System.currentTimeMillis();
83          for (int i = 0; i < nb; i ++) {
84              arrayFuture[i] = new R66Future(true);
85              BusinessRequestPacket packet = new BusinessRequestPacket(TestExecJavaTask.class.getName()+" business 0 other arguments", 0);
86              TestBusinessRequest transaction = new TestBusinessRequest(
87                      networkTransaction, arrayFuture[i], host.getHostid(),
88                      packet);
89              executorService.execute(transaction);
90          }
91          int success = 0;
92          int error = 0;
93          for (int i = 0; i < nb; i ++) {
94              arrayFuture[i].awaitUninterruptibly();
95              if (arrayFuture[i].isSuccess()) {
96                  success ++;
97              } else {
98                  error ++;
99              }
100         }
101         long time2 = System.currentTimeMillis();
102         logger.warn("Success: " + success + " Error: " + error + " NB/s: " +
103                 success * 100 * 1000 / (time2 - time1));
104         executorService.shutdown();
105         networkTransaction.closeAll();
106     }
107 
108 }