1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package openr66.protocol.test;
22
23 import goldengate.common.command.exception.CommandAbstractException;
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.DirectTransfer;
31 import openr66.context.ErrorCode;
32 import openr66.context.R66Result;
33 import openr66.database.DbConstant;
34 import openr66.protocol.configuration.Configuration;
35 import openr66.protocol.networkhandler.NetworkTransaction;
36 import openr66.protocol.utils.R66Future;
37
38 import org.jboss.netty.logging.InternalLoggerFactory;
39
40
41
42
43
44
45
46 public class TestTransferNoDb extends DirectTransfer {
47 static int nb = 100;
48
49
50
51
52
53 protected static boolean getSpecialParams(String []args, int rank) {
54 for (int i = rank; i<args.length; i++) {
55 if (args[i].equalsIgnoreCase("-nb")) {
56 i++;
57 nb = Integer.parseInt(args[i]);
58 } else if (args[i].equalsIgnoreCase("-md5")) {
59 } else if (args[i].charAt(0) == '-') {
60 i++;
61 }
62 }
63 return true;
64 }
65
66 public TestTransferNoDb(R66Future future, String remoteHost,
67 String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, long id,
68 NetworkTransaction networkTransaction) {
69 super(future, remoteHost, filename, rulename, fileinfo, isMD5, blocksize, id, networkTransaction);
70 }
71
72
73 public static void main(String[] args) {
74 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(
75 null));
76 if (logger == null) {
77 logger = GgInternalLoggerFactory.getLogger(DirectTransfer.class);
78 }
79 if (! getParams(args, false)) {
80 logger.error("Wrong initialization");
81 if (DbConstant.admin != null && DbConstant.admin.isConnected) {
82 DbConstant.admin.close();
83 }
84 System.exit(1);
85 }
86 getSpecialParams(args, 1);
87 Configuration.configuration.CLIENT_THREAD = nb;
88 Configuration.configuration.pipelineInit();
89 NetworkTransaction networkTransaction = new NetworkTransaction();
90 try {
91 ExecutorService executorService = Executors.newCachedThreadPool();
92
93 R66Future[] arrayFuture = new R66Future[nb];
94 logger.info("Start of Test Transfer");
95 long time1 = System.currentTimeMillis();
96 for (int i = 0; i < nb; i ++) {
97 arrayFuture[i] = new R66Future(true);
98 TestTransferNoDb transaction = new TestTransferNoDb(arrayFuture[i],
99 rhost, localFilename, rule, fileInfo, ismd5, block,
100 DbConstant.ILLEGALVALUE,
101 networkTransaction);
102 executorService.execute(transaction);
103 try {
104 Thread.sleep(10);
105 } catch (InterruptedException e) {
106 }
107 }
108 int success = 0;
109 int error = 0;
110 int warn = 0;
111 for (int i = 0; i < nb; i ++) {
112 arrayFuture[i].awaitUninterruptibly();
113 R66Result result = arrayFuture[i].getResult();
114 if (arrayFuture[i].isSuccess()) {
115 if (result.runner.getErrorInfo() == ErrorCode.Warning) {
116 warn ++;
117 } else {
118 success ++;
119 }
120 } else {
121 if (result.runner != null &&
122 result.runner.getErrorInfo() == ErrorCode.Warning) {
123 warn ++;
124 } else {
125 error ++;
126 }
127 }
128 }
129 long time2 = System.currentTimeMillis();
130 long length = 0;
131
132 R66Result result = arrayFuture[0].getResult();
133 logger.warn("Final file: " +
134 (result.file != null? result.file.toString() : "no file"));
135 try {
136 length = result.file != null? result.file.length() : 0L;
137 } catch (CommandAbstractException e) {
138 }
139 long delay = time2 - time1;
140 float nbs = success * 1000;
141 nbs /= delay;
142 float mbs = nbs * length / 1024;
143 logger.warn("Success: " + success + " Warning: " + warn + " Error: " +
144 error + " delay: " + delay + " NB/s: " + nbs + " KB/s: " + mbs);
145 executorService.shutdown();
146 } finally {
147 networkTransaction.closeAll();
148 }
149 }
150
151 }