/
RegressionSuite.java
224 lines (201 loc) · 7.5 KB
/
RegressionSuite.java
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
/* This file is part of VoltDB.
* Copyright (C) 2008-2010 VoltDB L.L.C.
*
* 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.
*/
package org.voltdb.regressionsuites;
import java.io.IOException;
import java.nio.channels.SocketChannel;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import junit.framework.TestCase;
import org.voltdb.CatalogContext;
import org.voltdb.catalog.Catalog;
import org.voltdb.client.Client;
import org.voltdb.client.ClientFactory;
import org.voltdb.client.ConnectionUtil;
import edu.brown.hstore.HStoreConstants;
import edu.brown.logging.LoggerUtil;
import edu.brown.rand.AbstractRandomGenerator;
import edu.brown.rand.DefaultRandomGenerator;
/**
* Base class for a set of JUnit tests that perform regression tests
* on a running VoltDB server. It is assumed that all tests will access
* a particular VoltDB server to do their work and check the output of
* any procedures called. The main feature of this class is that the
* backend instance of VoltDB is very flexible and the tests can be run
* on multiple instances of VoltDB to test different VoltDB topologies.
*
*/
public class RegressionSuite extends TestCase {
static {
// log4j Hack
LoggerUtil.setupLogging();
}
VoltServerConfig m_config;
protected String m_username = "default";
protected String m_password = "password";
private final ArrayList<Client> m_clients = new ArrayList<Client>();
private final ArrayList<SocketChannel> m_clientChannels = new ArrayList<SocketChannel>();
private final DefaultRandomGenerator random = new DefaultRandomGenerator();
/**
* Trivial constructor that passes parameter on to superclass.
* @param name The name of the method to run as a test. (JUnit magic)
*/
public RegressionSuite(final String name) {
super(name);
}
/**
* JUnit special method called to setup the test. This instance will start
* the VoltDB server using the VoltServerConfig instance provided.
*/
@Override
public void setUp() {
LoggerUtil.setupLogging();
m_config.startUp();
}
/**
* JUnit special method called to shutdown the test. This instance will
* stop the VoltDB server using the VoltServerConfig instance provided.
*/
@Override
public void tearDown() throws InterruptedException {
final List<String> valgrindErrors = m_config.shutDown();
if (valgrindErrors != null) {
String failString = "";
for (final String error : valgrindErrors) {
failString = failString + error;
}
fail(failString);
}
for (final Client c : m_clients) {
c.close();
}
synchronized (m_clientChannels) {
for (final SocketChannel sc : m_clientChannels) {
try {
ConnectionUtil.closeConnection(sc);
} catch (final IOException e) {
e.printStackTrace();
}
}
m_clientChannels.clear();
}
m_clients.clear();
System.gc();
}
/**
* @return Is the underlying instance of VoltDB running HSQL?
*/
public boolean isHSQL() {
return m_config.isHSQL();
}
/**
* @return Is the underlying instance of VoltDB running Valgrind with the IPC client?
*/
public boolean isValgrind() {
return m_config.isValgrind();
}
/**
* @return a reference to the associated VoltServerConfig
*/
public final VoltServerConfig getServerConfig() {
return m_config;
}
/**
* @return The catalog used in the internal cluster configuration
*/
@Deprecated
public final Catalog getCatalog() {
return m_config.getCatalog();
}
public final CatalogContext getCatalogContext() {
return m_config.getCatalogContext();
}
public final AbstractRandomGenerator getRandom() {
return (this.random);
}
/**
* Get a VoltClient instance connected to the server driven by the
* VoltServerConfig instance. Just pick from the list of listeners
* randomly.
*
* @return A VoltClient instance connected to the server driven by the
* VoltServerConfig instance.
*/
public Client getClient() throws IOException {
final List<String> listeners = m_config.getListenerAddresses();
final Random r = new Random();
final String listener = listeners.get(r.nextInt(listeners.size()));
final Client client = ClientFactory.createClient();
client.createConnection(null, listener, HStoreConstants.DEFAULT_PORT, m_username, m_password);
m_clients.add(client);
return client;
}
/**
* Release a client instance and any resources associated with it
*/
public void releaseClient(Client c) throws IOException, InterruptedException {
boolean removed = m_clients.remove(c);
assert(removed);
c.close();
}
/**
* Get a SocketChannel that is an authenticated connection to a server driven by the
* VoltServerConfig instance. Just pick from the list of listeners
* randomly.
*
* @return A SocketChannel that is already authenticated with the server
*/
public SocketChannel getClientChannel() throws IOException {
return getClientChannel(false);
}
public SocketChannel getClientChannel(final boolean noTearDown) throws IOException {
final List<String> listeners = m_config.getListenerAddresses();
final Random r = new Random();
final String listener = listeners.get(r.nextInt(listeners.size()));
final SocketChannel channel = (SocketChannel)
ConnectionUtil.getAuthenticatedConnection(
listener,
m_username, m_password, HStoreConstants.DEFAULT_PORT)[0];
channel.configureBlocking(true);
if (!noTearDown) {
synchronized (m_clientChannels) {
m_clientChannels.add(channel);
}
}
return channel;
}
/**
* Protected method used by MultiConfigSuiteBuilder to set the VoltServerConfig
* instance a particular test will run with.
*
* @param config An instance of VoltServerConfig to run tests with.
*/
void setConfig(final VoltServerConfig config) {
m_config = config;
}
@Override
public String getName() {
// munge the test name with the VoltServerConfig instance name
return super.getName() + "-" + m_config.getName();
}
}