Skip to content

Commit 95f54f4

Browse files
committed
Improving Logging in ConnectionManipulationProxyServer to aid diagnosis of timing based issues in Java v3 test failures.
Signed-off-by: James Sutton <james.sutton@uk.ibm.com>
1 parent d462aeb commit 95f54f4

2 files changed

Lines changed: 21 additions & 13 deletions

File tree

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/automaticReconnect/OfflineBufferingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void testManyMessageBufferAndDeliver() throws Exception {
178178
IMqttToken subConnectToken = subClient.connect();
179179
subConnectToken.waitForCompletion(5000);
180180
// Subscribe to topic
181-
subClient.subscribe(topicPrefix + methodName, 0);
181+
subClient.subscribe(topicPrefix + methodName, 1);
182182

183183
// Enable Proxy & Connect to server
184184
proxy.enableProxy();
@@ -225,7 +225,7 @@ public void testManyMessageBufferAndDeliver() throws Exception {
225225

226226
// Check that all messages have been delivered
227227
for (int x = 0; x < 100; x++) {
228-
boolean recieved = mqttV3Receiver.validateReceipt(topicPrefix + methodName, 0, Integer.toString(x).getBytes());
228+
boolean recieved = mqttV3Receiver.validateReceipt(topicPrefix + methodName, 1, Integer.toString(x).getBytes());
229229
Assert.assertTrue(recieved);
230230
}
231231
log.info("All messages sent and Recieved correctly.");

org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test/utilities/ConnectionManipulationProxyServer.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public ConnectionManipulationProxyServer(String host, int remotePort, int localP
3434
}
3535

3636
public void startProxy(){
37+
log.info("[CPMS Proxy] - Starting Proxy");
3738
synchronized (enableLock) {
3839
enableProxy = true;
3940
}
@@ -42,6 +43,7 @@ public void startProxy(){
4243
}
4344

4445
public void enableProxy(){
46+
log.info("[CPMS Proxy] - Enabling Proxy");
4547
synchronized (enableLock) {
4648
enableProxy = true;
4749
}
@@ -52,6 +54,7 @@ public void enableProxy(){
5254
}
5355

5456
public void disableProxy(){
57+
log.info("[CPMS Proxy] - Disabling Proxy");
5558
synchronized (enableLock) {
5659
enableProxy = false;
5760
}
@@ -66,6 +69,7 @@ public void disableProxy(){
6669
}
6770

6871
public void stopProxy(){
72+
log.info("[CPMS Proxy] - Stopping Proxy");
6973
synchronized (enableLock) {
7074
enableProxy = false;
7175
}
@@ -74,6 +78,7 @@ public void stopProxy(){
7478
}
7579

7680
private void killOpenSockets(){
81+
log.info("[CPMS Proxy] - killOpenSockets Called.");
7782
try {
7883
if(serverSocket != null){
7984
serverSocket.close();
@@ -91,6 +96,7 @@ private void killOpenSockets(){
9196

9297
@Override
9398
public void run() {
99+
log.info("[CPMS Proxy] - Proxy Thread running.");
94100
try {
95101

96102
final byte[] request = new byte[1024];
@@ -116,13 +122,14 @@ public void run() {
116122

117123

118124

119-
//log.fine("Proxy: Waiting for incoming connection");
125+
log.info("[CPMS Proxy] - Waiting for incoming connection..");
120126

121127
try {
122128
// Wait for a connection on the local Port
123129
client = serverSocket.accept();
124130

125-
log.fine("Proxy: Client Opened Connection to Proxy...");
131+
132+
log.info("[CPMS Proxy] - Client Opened Connection to Proxy...");
126133

127134
final InputStream streamFromClient = client.getInputStream();
128135
final OutputStream streamToClient = client.getOutputStream();
@@ -135,7 +142,7 @@ public void run() {
135142
client.close();
136143
continue;
137144
}
138-
log.fine("Proxy: Proxy Connected to Server");
145+
log.info("Proxy: Proxy Connected to Server");
139146

140147
// Get Server Streams
141148
final InputStream streamFromServer = server.getInputStream();
@@ -150,7 +157,7 @@ public void run() {
150157
streamToServer.flush();
151158
}
152159
} catch (IOException ex){
153-
//log.warning("Proxy: 1 Connection lost: " + ex.getMessage());
160+
log.warning("[CPMS Proxy] - IOException in client to server stream: " + ex.getMessage());
154161
try {
155162
client.close();
156163
server.close();
@@ -173,7 +180,8 @@ public void run() {
173180
}
174181

175182
} catch (IOException ex){
176-
//log.warning("Proxy: 2 Connection lost: " + ex.getMessage());
183+
log.warning("[CPMS Proxy] - IOException in server to client stream: " + ex.getMessage());
184+
log.info("[CPMS Proxy] - ");
177185
client.close();
178186
server.close();
179187
}
@@ -182,8 +190,7 @@ public void run() {
182190

183191

184192
} catch (IOException ex) {
185-
//log.warning("Proxy: 3 Connection lost: " + ex.getMessage());
186-
//ex.printStackTrace();
193+
log.warning("[CPMS Proxy] - General IO Exception caught in main Thread: " + ex.getMessage());
187194
break;
188195
} finally {
189196
try {
@@ -194,22 +201,23 @@ public void run() {
194201
client.close();
195202
}
196203
} catch(IOException ex) {
197-
//log.warning("Proxy: 4 Connection lost: " + ex.getMessage());
204+
log.warning("[CPMS Proxy] - IOException caught whilst closing proxy connection.: " + ex.getMessage());
198205
}
199206
}
200207

201208

202209

203210
}
204211
}
205-
log.fine("Proxy: Proxy Thread finishing..");
212+
log.info("[CPMS Proxy] - Proxy Thread finishing..");
213+
206214
if(!serverSocket.isClosed()){
207215
serverSocket.close();
208216
}
209-
log.fine("Proxy: Server Socket Closed, returning...");
217+
log.info("[CPMS Proxy] - Server Socket Closed, returning...");
210218

211219
} catch(IOException ex) {
212-
log.warning("Proxy: 5 Thread Connection lost: " + ex.getMessage());
220+
log.warning("[CPMS Proxy] - Thread Connection lost: " + ex.getMessage());
213221
ex.printStackTrace();
214222
}
215223

0 commit comments

Comments
 (0)