forked from VoltDB/voltdb-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenerateTestFiles.java
More file actions
237 lines (209 loc) · 8.75 KB
/
Copy pathGenerateTestFiles.java
File metadata and controls
237 lines (209 loc) · 8.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/* This file is part of VoltDB.
* Copyright (C) 2008-2010 VoltDB Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
import org.voltdb.*;
import org.voltdb.client.*;
import org.voltdb.*;
import org.voltdb.VoltTable.ColumnInfo;
import java.io.IOException;
import java.nio.*;
import java.nio.channels.*;
import java.net.*;
import java.io.*;
import org.voltdb.types.*;
import java.math.*;
import org.voltdb.messaging.*;
public class GenerateTestFiles {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.socket().bind(new InetSocketAddress("localhost", 21212));
final org.voltdb.client.Client client = ClientFactory.createClient();
Thread clientThread = new Thread() {
@Override
public void run() {
try {
client.createConnection( "localhost", "hello", "world");
client.callProcedure("Insert", "Hello", "World", "English");
try {
client.callProcedure("Insert", "Hello", "World", "English");
} catch (Exception e) {
}
client.callProcedure("Select", "English");
client.callProcedure(new NullCallback(), "@Shutdown");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
clientThread.setDaemon(true);
clientThread.start();
SocketChannel sc = ssc.accept();
sc.socket().setTcpNoDelay(true);
ByteBuffer message = ByteBuffer.allocate(8096);
sc.configureBlocking(true);
int read = sc.read(message);
message.flip();
FileOutputStream fos = new FileOutputStream("authentication_request.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
ssc.close();
System.out.print("Start a fresh VoltDB server with the HelloWorld example and authentication disabled so that an authentication request can be generated and the response read back as well as a few procedure invocations and then press enter");
System.in.read();
final SocketChannel voltsc = SocketChannel.open(new InetSocketAddress("localhost", 21212));
voltsc.socket().setTcpNoDelay(true);
voltsc.configureBlocking(true);
voltsc.write(message);
message.clear();
voltsc.read(message);
message.flip();
ByteBuffer authenticationResponse = ByteBuffer.allocate(message.remaining());
authenticationResponse.put(message);
message.flip();
authenticationResponse.flip();
fos = new FileOutputStream("authentication_response.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
sc.write(message);
message.clear();
sc.read(message);
message.flip();
fos = new FileOutputStream("invocation_request_success.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
voltsc.write(message);
message.clear();
voltsc.read(message);
message.flip();
fos = new FileOutputStream("invocation_response_success.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
sc.write(message);
message.clear();
sc.read(message);
message.flip();
fos = new FileOutputStream("invocation_request_fail_cv.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
voltsc.write(message);
message.clear();
voltsc.read(message);
message.flip();
fos = new FileOutputStream("invocation_response_fail_cv.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
sc.write(message);
message.clear();
sc.read(message);
message.flip();
fos = new FileOutputStream("invocation_request_select.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
voltsc.write(message);
message.clear();
voltsc.read(message);
message.flip();
fos = new FileOutputStream("invocation_response_select.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
sc.write(message);
message.clear();
sc.read(message);
message.flip();
voltsc.write(message);
voltsc.close();
sc.close();
clientThread.join();
client.close();
Thread.sleep(3000);
ssc = ServerSocketChannel.open();
ssc.socket().bind(new InetSocketAddress("localhost", 21212));
clientThread = new Thread() {
@Override
public void run() {
try {
org.voltdb.client.Client newClient = ClientFactory.createClient();
newClient.createConnection( "localhost", "hello", "world");
String strings[] = new String[] { "oh", "noes" };
byte bytes[] = new byte[] { 22, 33, 44 };
short shorts[] = new short[] { 22, 33, 44 };
int ints[] = new int[] { 22, 33, 44 };
long longs[] = new long[] { 22, 33, 44 };
double doubles[] = new double[] { 3, 3.1, 3.14, 3.1459 };
TimestampType timestamps[] = new TimestampType[] { new TimestampType(33), new TimestampType(44) };
BigDecimal bds[] = new BigDecimal[] { new BigDecimal( "3" ), new BigDecimal( "3.14" ), new BigDecimal( "3.1459" ) };
try {
newClient.callProcedure("foo", strings, bytes, shorts, ints, longs, doubles, timestamps, bds, null, "ohnoes!", (byte)22, (short)22, 22, (long)22, 3.1459, new TimestampType(33), new BigDecimal("3.1459"));
} catch (Exception e) {}
} catch (Exception e) {
e.printStackTrace();
}
}
};
clientThread.setDaemon(true);
clientThread.start();
sc = ssc.accept();
message.clear();
sc.read(message);
sc.write(authenticationResponse);
message.clear();
read = sc.read(message);
sc.close();
message.flip();
fos = new FileOutputStream("invocation_request_all_params.msg");
fos.write(message.array(), 0, message.remaining());
fos.flush();
fos.close();
ColumnInfo columns[] = new ColumnInfo[] {
new ColumnInfo("column1", VoltType.TINYINT),
new ColumnInfo("column2", VoltType.STRING),
new ColumnInfo("column3", VoltType.SMALLINT),
new ColumnInfo("column4", VoltType.INTEGER),
new ColumnInfo("column5", VoltType.BIGINT),
new ColumnInfo("column6", VoltType.TIMESTAMP),
new ColumnInfo("column7", VoltType.DECIMAL)
};
VoltTable vt = new VoltTable(columns);
vt.addRow( null, null, null, null, null, null, null);
vt.addRow( 0, "", 2, 4, 5, new TimestampType(44), new BigDecimal("3.1459"));
vt.addRow( 0, null, 2, 4, 5, null, null);
vt.addRow( null, "woobie", null, null, null, new TimestampType(44), new BigDecimal("3.1459"));
FastSerializer fs = new FastSerializer();
fs.writeObject(vt);
fos = new FileOutputStream("serialized_table.bin");
fos.write(fs.getBytes());
fos.flush();
fos.close();
clientThread.join();
}
}