📄 invoketestcase.java
字号:
assertEquals(Integer.MIN_VALUE, echo.echoInt(Integer.MIN_VALUE));
assertEquals(Integer.MAX_VALUE, echo.echoInt(Integer.MAX_VALUE));
assertEquals(Long.MIN_VALUE, echo.echoLong(Long.MIN_VALUE));
assertEquals(Long.MAX_VALUE, echo.echoLong(Long.MAX_VALUE));
assertEquals(Float.MIN_VALUE, echo.echoFloat(Float.MIN_VALUE), 0.0f);
assertEquals(Float.MAX_VALUE, echo.echoFloat(Float.MAX_VALUE), 0.0f);
assertEquals(Double.MIN_VALUE, echo.echoDouble(Double.MIN_VALUE), 0.0);
assertEquals(Double.MAX_VALUE, echo.echoDouble(Double.MAX_VALUE), 0.0);
}
/**
* Tests remote method invocation for primitive arrays.
*
* @throws Exception for any error
*/
public void testPrimitiveArrays() throws Exception {
final int size = 4096;
Registry registry = _orb.getRegistry(getConnectionProperties());
EchoService echo = (EchoService) registry.lookup(ECHO_SERVICE);
// byte arrays
byte[] bytes = new byte[size];
for (int i = 0; i < bytes.length; ++i) {
bytes[i] = (byte) i;
}
byte[] bytesResult = (byte[]) echo.echoObject(bytes);
assertTrue(Arrays.equals(bytes, bytesResult));
// int arrays
int[] ints = new int[size];
for (int i = 0; i < ints.length; ++i) {
ints[i] = (int) i;
}
int[] intsResult = (int[]) echo.echoObject(ints);
assertTrue(Arrays.equals(ints, intsResult));
// float arrays
float[] floats = new float[size];
for (int i = 0; i < floats.length; ++i) {
floats[i] = i;
}
float[] floatsResult = (float[]) echo.echoObject(floats);
assertTrue(Arrays.equals(floats, floatsResult));
}
/**
* Verifies invocations can be made concurrently.
*
* @throws Exception for any error
*/
public void testConcurrency() throws Exception {
Thread[] threads = new Thread[10];
Registry registry = _orb.getRegistry(getConnectionProperties());
EchoService echo = (EchoService) registry.lookup(ECHO_SERVICE);
for (int i = 0; i < threads.length; ++i) {
threads[i] = new Thread(new IntInvoker(echo, i, 1000));
}
for (int i = 0; i < threads.length; ++i) {
threads[i].start();
}
for (int i = 0; i < threads.length; ++i) {
try {
threads[i].join();
} catch (InterruptedException ignore) {
}
}
if (_failure != null) {
if (_failure instanceof Error) {
throw (Error) _failure;
} else if (_failure instanceof Exception) {
throw (Exception) _failure;
} else {
throw new Exception("testConcurrency failed: "
+ _failure.getMessage());
}
}
}
/**
* Returns connection properties for establishing a connection to the remote
* ORB.
*
* @return the connection properties, or <code>null</code> if the default
* connection properties should be used
* @throws IOException if a store cannot be found
*/
protected Map getConnectionProperties() throws IOException {
Map properties = new HashMap();
properties.put(ORB.PROVIDER_URI, getServerURI());
if (_connectionProps != null) {
properties.putAll(_connectionProps);
}
return properties;
}
/**
* Returns the acceptor properties to use when accepting connections.
*
* @return the acceptor properties, or <code>null</code> if the default
* connection properties should be used
* @throws Exception for any error
*/
protected Map getAcceptorProperties() throws Exception {
Map properties = new HashMap();
properties.put(ORB.PROVIDER_URI, _uri);
if (_acceptorProps != null) {
properties.putAll(_acceptorProps);
}
return properties;
}
/**
* Helper to return the server URI.
*
* @return the server URI
*/
protected String getServerURI() {
return (_routeURI != null) ? _routeURI : _uri;
}
/**
* Sets up the test case.
*
* @throws Exception for any error
*/
protected void setUp() throws Exception {
_log.debug("setUp() [test=" + getName() + ", uri=" + _uri + "]");
_orb = ORBFactory.createORB(getAcceptorProperties());
if (_routeURI != null) {
_orb.addRoute(_uri, _routeURI);
}
if (_embeddedService) {
Registry serverRegistry = _orb.getRegistry();
Proxy proxy = _orb.exportObject(new EchoServiceImpl());
serverRegistry.bind(ECHO_SERVICE, proxy);
} else {
Properties props = new Properties();
final String key = "log4j.configuration";
String log4j = System.getProperty(key);
if (log4j != null) {
props.setProperty("log4j.configuration", key);
}
_jvm = new JVM(EchoServer.class.getName(), null, props,
getServerURI());
_jvm.start();
// give the JVM time to start
Thread.sleep(2000);
}
}
/**
* Cleans up the test case
*
* @throws Exception for any error
*/
protected void tearDown() throws Exception {
_log.debug("tearDown() [test=" + getName() + ", uri=" + _uri + "]");
_orb.shutdown();
if (!_embeddedService && _jvm != null) {
_jvm.stop();
_jvm.waitFor();
}
// reset any SSL properties that may have been set.
SSLUtil.clearProperties();
}
/**
* Helper classed used in concurrency tests.
*/
private class IntInvoker implements Runnable {
/**
* The echo service.
*/
private final EchoService _echo;
/**
* The value to invoke the service with.
*/
private final int _value;
/**
* No. of invocations to perform.
*/
private final int _count;
/**
* Construct a new <code>IntInvoker</code>.
*
* @param echo the echo service
* @param value the value to invoke the echo service with
* @param count the no. of invocations to perform
*/
public IntInvoker(EchoService echo, int value, int count) {
_echo = echo;
_value = value;
_count = count;
}
/**
* Run the invoker.
*/
public void run() {
try {
for (int i = 0; i < _count; ++i) {
assertEquals(_value, _echo.echoInt(_value));
}
} catch (Throwable exception) {
_failure = exception;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -