Skip to content
Permalink
Browse files
Merge branch 'nr.dev' into 'ibm-trunk'
Nr.dev

Further fixes for customer-reported problems

See merge request !68
  • Loading branch information
ngmr committed Jun 21, 2016
2 parents 2550cc0 + f7c60ed commit bc1c6a40fce992bfe042b59d9307963683ef467a
Showing 9 changed files with 148 additions and 270 deletions.
@@ -459,6 +459,7 @@ public org.apache.yoko.orb.OCI.ConnectorInfo get_info() {
// ------------------------------------------------------------------

private Connector_impl(IOR ior, Policy[] policies, String host, int port, boolean keepAlive, ConnectCB[] cb, ListenerMap lm, ConnectionHelper helper, ExtendedConnectionHelper xhelper, Codec codec) {
if ((null == helper) && (null == xhelper)) throw new IllegalArgumentException("Both connection helpers must not be null");
ior_ = ior;
policies_ = policies;
keepAlive_ = keepAlive;
@@ -474,8 +475,8 @@ public Connector_impl(IOR ior, Policy[] policies, String host, int port, boolean
this(ior, policies, host, port, keepAlive, cb, lm, helper, null, codec);
}

public Connector_impl(IOR ior, Policy[] policies, String host, int port, boolean keepAlive, ConnectCB[] cb, ListenerMap lm, ExtendedConnectionHelper helper, Codec codec) {
this(ior, policies, host, port, keepAlive, cb, lm, null, helper, codec);
public Connector_impl(IOR ior, Policy[] policies, String host, int port, boolean keepAlive, ConnectCB[] cb, ListenerMap lm, ExtendedConnectionHelper xhelper, Codec codec) {
this(ior, policies, host, port, keepAlive, cb, lm, null, xhelper, codec);
}

public void finalize() throws Throwable {
@@ -97,9 +97,6 @@ protected void runServerClientTest(String serverClass, String[] serverArgs,
server.launch();
Future<Void> serverFuture = server.invokeMainAsync(serverClass, serverArgs);
waitForFile();
// TODO: Need to find a better way, this slows down testing unneccesarily,
// and is somewhat non-robust.
Thread.sleep(1000);
client.invokeMain(clientClass, clientArgs);
try {
serverFuture.get(2, SECONDS);
@@ -17,47 +17,48 @@

package test.poa;

import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POAPackage.*;
import java.io.*;
import java.util.concurrent.CountDownLatch;

final class PMSTestThread extends Thread {
private Test test_;
private final Test test_;

private int state_;
private final CountDownLatch startLatch = new CountDownLatch(1);
public volatile Result result = null;

final static int NONE = 0;

final static int CALL_STARTED = 1;

final static int CALL_FAILURE = 2;

final static int CALL_SUCCESS = 3;

private synchronized void setState(int val) {
state_ = val;
}
public enum Result { SUCCESS, FAILURE, ERROR };

public void run() {
setState(CALL_STARTED);
startLatch.countDown();
try {
test_.aMethod();
result = Result.SUCCESS;
} catch (org.omg.CORBA.TRANSIENT ex) {
setState(CALL_FAILURE);
result = Result.FAILURE;
return;
} catch (org.omg.CORBA.SystemException ex) {
result = Result.ERROR;
System.err.println("Unexpected: " + ex);
}
setState(CALL_SUCCESS);
}

synchronized int callState() {
return state_;
public void waitForStart() {
do {
try {
startLatch.await();
return;
} catch (InterruptedException ie) {}
} while (true);
}

public void waitForEnd() {
while (isAlive()) {
try {
join();
} catch (InterruptedException ie) {}
}
}

PMSTestThread(Test test) {
test_ = test;
state_ = NONE;
}
}
@@ -17,135 +17,78 @@

package test.poa;

import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

public final class TestDispatchStrategyServer extends test.common.TestBase {
//
// Implementation to test same thread dispatch strategy
//
final static class TestSameThread_impl extends TestPOA {
private Thread thread_;
abstract static class AbstractTest extends TestPOA {
private volatile boolean failed = false;

private boolean failed_;

private boolean first_;
public final boolean failed() {
return failed;
}

TestSameThread_impl() {
failed_ = false;
first_ = true;
protected void fail() {
failed = true;
}
}

public void aMethod() {
//
// Test to ensure that all requests handled by the same thread
//
if (first_) {
thread_ = Thread.currentThread();
first_ = false;
} else if (!Thread.currentThread().equals(thread_)) {
failed_ = true;
}
abstract static class AbstractTestPool extends AbstractTest {
private final Set<Thread> threadSet = new HashSet<>();
private final int maxSize;

try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
AbstractTestPool(int maxSize) {
this.maxSize = maxSize;
}

public boolean failed() {
return failed_;
public final synchronized void aMethod() {
final Thread thisThread = Thread.currentThread();
if (threadSet.contains(thisThread)) return;
if (threadSet.size() < maxSize) {
threadSet.add(thisThread);
return;
}
fail();
}
}

final static class TestSameThread_impl extends AbstractTestPool {
TestSameThread_impl() { super(1); }
}

//
// Implementation to test thread per request dispatch strategy
//
final static class TestThreadPerReq_impl extends TestPOA {
private Thread threads_[];

private int thread_count_;

private boolean failed_;

TestThreadPerReq_impl() {
failed_ = false;
thread_count_ = 0;
threads_ = new Thread[5];
}

public void aMethod() {
int idx;
synchronized (this) {
//
// Test to ensure that each request is being handled
// by a different thread.
//
for (idx = 0; idx < thread_count_; idx++) {
if (Thread.currentThread().equals(threads_[idx]))
failed_ = true;
}

if (idx == thread_count_) {
threads_[thread_count_++] = Thread.currentThread();
}
}
final static class TestThreadPerReq_impl extends AbstractTest {
private final Set<Thread> threadSet = new HashSet<>();

try {
Thread.sleep(100);
} catch (InterruptedException ex) {
public synchronized void aMethod() {
final Thread thisThread = Thread.currentThread();
//
// Test to ensure that each request is being handled
// by a different thread.
//
if (threadSet.contains(thisThread)) {
fail();
return;
}
}

public boolean failed() {
return failed_;
threadSet.add(thisThread);
}
}

//
// Implementation to test thread pool dispatch strategy
//
final static class TestThreadPool_impl extends TestPOA {
private Thread threads_[];

private int thread_count_;

private boolean failed_;

TestThreadPool_impl() {
failed_ = false;
thread_count_ = 0;
threads_ = new Thread[2];
}

public void aMethod() {
synchronized (this) {
//
// Test to ensure that all requests are handled only by
// the two threads in the thread pool.
//
if (thread_count_ == 0) {
threads_[0] = Thread.currentThread();
++thread_count_;
} else if (!Thread.currentThread().equals(threads_[0])) {
if (thread_count_ == 1) {
threads_[1] = Thread.currentThread();
++thread_count_;
} else if (!Thread.currentThread().equals(threads_[1])) {
failed_ = true;
}
}
}

try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}

public boolean failed() {
return failed_;
}
final static class TestThreadPool_impl extends AbstractTestPool {
TestThreadPool_impl() { super(2); }
}

//

0 comments on commit bc1c6a4

Please sign in to comment.