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.GgInternalLoggerFactory;
24  import goldengate.common.logging.GgSlf4JLoggerFactory;
25  
26  import java.sql.Timestamp;
27  import java.util.concurrent.ExecutorService;
28  import java.util.concurrent.Executors;
29  
30  import openr66.client.SubmitTransfer;
31  import openr66.database.DbConstant;
32  import openr66.protocol.utils.R66Future;
33  
34  import org.jboss.netty.logging.InternalLoggerFactory;
35  
36  /**
37   * Test class for multiple SubmitTransfer
38   *
39   * @author Frederic Bregier
40   *
41   */
42  public class TestSubmitTransfer extends SubmitTransfer {
43      static int nb = 100;
44      /**
45       * @param args
46       * @param rank
47       * @return True if OK
48       */
49      protected static boolean getSpecialParams(String []args, int rank) {
50          for (int i = rank; i<args.length; i++) {
51              if (args[i].equalsIgnoreCase("-nb")) {
52                  i++;
53                  nb = Integer.parseInt(args[i]);
54              } else if (args[i].equalsIgnoreCase("-md5")) {
55              } else if (args[i].charAt(0) == '-') {
56                  i++;// jump one
57              }
58          }
59          return true;
60      }
61  
62      public TestSubmitTransfer(R66Future future, String remoteHost,
63              String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, 
64              Timestamp starttime) {
65          super(future, remoteHost, filename, rulename, fileinfo, isMD5, blocksize, 
66                  DbConstant.ILLEGALVALUE, starttime);
67      }
68  
69      public static void main(String[] args) {
70          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(
71                  null));
72          if (logger == null) {
73              logger = GgInternalLoggerFactory.getLogger(SubmitTransfer.class);
74          }
75          if (! getParams(args, true)) {
76              logger.error("Wrong initialization");
77              if (DbConstant.admin != null && DbConstant.admin.isConnected) {
78                  DbConstant.admin.close();
79              }
80              System.exit(1);
81          }
82          getSpecialParams(args, 1);
83  
84          ExecutorService executorService = Executors.newCachedThreadPool();
85          R66Future[] arrayFuture = new R66Future[nb];
86  
87          logger.warn("Start Test Submit");
88          for (int i = 0; i < nb; i ++) {
89              arrayFuture[i] = new R66Future(true);
90              Timestamp newstart = ttimestart;
91              if (newstart != null) {
92                  // delay of 10 ms between each
93                  newstart = new Timestamp(newstart.getTime()+i*10);
94              }
95              TestSubmitTransfer transaction = new TestSubmitTransfer(arrayFuture[i],
96                      rhost, localFilename, rule, fileInfo, ismd5, block, newstart);
97              //executorService.execute(transaction);
98              transaction.run();
99          }
100         int success = 0;
101         int error = 0;
102         for (int i = 0; i < nb; i ++) {
103             arrayFuture[i].awaitUninterruptibly();
104             if (arrayFuture[i].isSuccess()) {
105                 success ++;
106             } else {
107                 error ++;
108             }
109         }
110         executorService.shutdown();
111         logger.warn("Prepare transfer Success: " + success + " Error: " + error);
112     }
113 
114 }