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  import openr66.client.RecvThroughClient;
26  import openr66.client.RecvThroughHandler;
27  import openr66.context.ErrorCode;
28  import openr66.context.R66Result;
29  import openr66.database.DbConstant;
30  import openr66.protocol.configuration.Configuration;
31  import openr66.protocol.exception.OpenR66ProtocolBusinessException;
32  import openr66.protocol.networkhandler.NetworkTransaction;
33  import openr66.protocol.utils.R66Future;
34  
35  import org.jboss.netty.buffer.ChannelBuffer;
36  import org.jboss.netty.logging.InternalLoggerFactory;
37  
38  /**
39   * Test class for Recv Through client
40   *
41   * @author Frederic Bregier
42   *
43   */
44  public class TestRecvThroughClient extends RecvThroughClient {
45      public static class TestRecvThroughHandler extends RecvThroughHandler {
46  
47          /* (non-Javadoc)
48           * @see openr66.client.RecvThroughHandler#writeChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)
49           */
50          @Override
51          public void writeChannelBuffer(ChannelBuffer buffer)
52                  throws OpenR66ProtocolBusinessException {
53              buffer.skipBytes(buffer.readableBytes());
54              //byte [] array = this.getByte(buffer);
55              // FIXME one should use the array for its own goal
56              //logger.debug("Write {}", array.length);
57          }
58  
59      }
60      /**
61       * @param future
62       * @param remoteHost
63       * @param filename
64       * @param rulename
65       * @param fileinfo
66       * @param isMD5
67       * @param blocksize
68       * @param networkTransaction
69       */
70      public TestRecvThroughClient(R66Future future, TestRecvThroughHandler handler,
71              String remoteHost,
72              String filename, String rulename, String fileinfo, boolean isMD5,
73              int blocksize, NetworkTransaction networkTransaction) {
74          super(future, handler, remoteHost, filename, rulename, fileinfo, isMD5, blocksize,
75                  DbConstant.ILLEGALVALUE, networkTransaction);
76      }
77  
78      /**
79       * @param args
80       */
81      public static void main(String[] args) {
82          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
83          if (logger == null) {
84              logger = GgInternalLoggerFactory.getLogger(TestRecvThroughHandler.class);
85          }
86          if (! getParams(args, false)) {
87              logger.error("Wrong initialization");
88              if (DbConstant.admin != null && DbConstant.admin.isConnected) {
89                  DbConstant.admin.close();
90              }
91              System.exit(1);
92          }
93          Configuration.configuration.pipelineInit();
94          NetworkTransaction networkTransaction = new NetworkTransaction();
95          try {
96              R66Future future = new R66Future(true);
97              TestRecvThroughHandler handler = new TestRecvThroughHandler();
98              TestRecvThroughClient transaction = new TestRecvThroughClient(future,
99                      handler,
100                     rhost, localFilename, rule, fileInfo, ismd5, block,
101                     networkTransaction);
102             long time1 = System.currentTimeMillis();
103             transaction.run();
104             future.awaitUninterruptibly();
105 
106             long time2 = System.currentTimeMillis();
107             long delay = time2 - time1;
108             R66Result result = future.getResult();
109             if (future.isSuccess()) {
110                 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
111                     logger.warn("Warning with Id: " +
112                             result.runner.getSpecialId()+" on file: " +
113                             (result.file != null? result.file.toString() : "no file")
114                             +" delay: "+delay);
115                 } else {
116                     logger.warn("Success with Id: " +
117                             result.runner.getSpecialId()+" on Final file: " +
118                             (result.file != null? result.file.toString() : "no file")
119                             +" delay: "+delay);
120                 }
121             } else {
122                 if (result == null || result.runner == null) {
123                     logger.warn("Transfer in Error with no Id", future.getCause());
124                     networkTransaction.closeAll();
125                     System.exit(1);
126                 }
127                 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
128                     logger.warn("Transfer in Warning with Id: " +
129                             result.runner.getSpecialId(), future.getCause());
130                     networkTransaction.closeAll();
131                     System.exit(result.code.ordinal());
132                 } else {
133                     logger.error("Transfer in Error with Id: " +
134                             result.runner.getSpecialId(), future.getCause());
135                     networkTransaction.closeAll();
136                     System.exit(result.code.ordinal());
137                 }
138             }
139         } finally {
140             networkTransaction.closeAll();
141         }
142 
143     }
144 
145 }