Skip to content

Commit

Permalink
TEIID-5054 fixing failing ping
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Sep 6, 2017
1 parent 5e8f4ad commit 17714d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Expand Up @@ -318,9 +318,10 @@ public void read(long timeout, TimeUnit unit, ResultsFuture<?> future) throws Ti
}
}
if (reading) {
Object message = null;
try {
if (!future.isDone()) {
receivedMessage(socketChannel.read());
message = socketChannel.read();
}
} catch (SocketTimeoutException e) {
} catch (Exception e) {
Expand All @@ -331,6 +332,10 @@ public void read(long timeout, TimeUnit unit, ResultsFuture<?> future) throws Ti
this.notifyAll();
}
}
if (message != null) {
//process after reading to prevent recurrent reading with hasReader=true
receivedMessage(message);
}
}
if (!future.isDone()) {
long now = System.currentTimeMillis();
Expand Down
20 changes: 19 additions & 1 deletion runtime/src/test/java/org/teiid/transport/TestCommSockets.java
Expand Up @@ -37,6 +37,8 @@
import org.junit.Before;
import org.junit.Test;
import org.teiid.client.security.ILogon;
import org.teiid.client.util.ResultsFuture;
import org.teiid.client.util.ResultsFuture.CompletionListener;
import org.teiid.common.buffer.BufferManagerFactory;
import org.teiid.common.buffer.impl.MemoryStorageManager;
import org.teiid.core.crypto.NullCryptor;
Expand Down Expand Up @@ -177,7 +179,7 @@ public ClassLoader getCallerClassloader() {
assertEquals(0, stats.sockets);
}

Properties p = new Properties();
Properties p = new Properties(socketConfig);
String url = new TeiidURL(addr.getHostName(), listener.getPort(), clientSecure).getAppServerURL();
p.setProperty(TeiidURL.CONNECTION.SERVER_URL, url);
p.setProperty(TeiidURL.CONNECTION.APP_NAME, "test");
Expand Down Expand Up @@ -357,4 +359,20 @@ private void helpTestNewInstance(Properties p)
helpEstablishConnection(true, config, p);
}

@Test(timeout=19000) public void testAutoFailoverPing() throws Exception {
Properties p = new Properties();
p.setProperty(TeiidURL.CONNECTION.AUTO_FAILOVER, "true");
p.setProperty("org.teiid.sockets.synchronousttl", "20000");
SocketServerConnection conn = helpEstablishConnection(false, new SSLConfiguration(), p);
final FakeService fs = conn.getService(FakeService.class);
ResultsFuture<Integer> future = fs.delayedAsynchResult();
future.addCompletionListener(new CompletionListener<Integer>() {
@Override
public void onCompletion(ResultsFuture<Integer> future) {
fs.asynchResult(); //potentially recurrent;
}
});
future.get();
}

}
Expand Up @@ -72,7 +72,9 @@ public interface FakeService {

ResultsFuture<Integer> asynchResult();

String exceptionMethod() throws TeiidProcessingException;
ResultsFuture<Integer> delayedAsynchResult();

String exceptionMethod() throws TeiidProcessingException;

int lobMethod(InputStream is, Reader r) throws IOException;

Expand Down Expand Up @@ -102,6 +104,17 @@ public Reader getReader() throws IOException {
return new StringReader("hello world"); //$NON-NLS-1$
}

@Override
public ResultsFuture<Integer> delayedAsynchResult() {
ResultsFuture<Integer> result = new ResultsFuture<Integer>();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
}
result.getResultsReceiver().receiveResults(new Integer(5));
return result;
}

}

private static class FakeClientServerInstance extends SocketServerInstanceImpl implements ClientInstance {
Expand Down

0 comments on commit 17714d5

Please sign in to comment.