// The object to handle the requrest is selected randomly.
// The acceleration factor will be lower than the number
// of the "parallelized objects". This is sufficient
// as this is just a test, not a real distribute computing task.
Request rq =
objects [ rn ]._create_request(null, "sleep_and_return",
orb.create_list(1), null
);
rq.set_return_type(orb.get_primitive_tc(TCKind.tk_long));
rq.add_in_arg().insert_long(times [ i ]);
reqs [ i ] = rq;
}
long started = System.currentTimeMillis();
orb.send_multiple_requests_deferred(reqs);
// Be sure the execution has returned correctly.
assertTrue("Hangs on orb.send_multiple_requests_defferred",
System.currentTimeMillis() < started + 199
);
assertTrue("orb.send_multiple_requests_defferred:"+
"Cannot be ready immediately",
!orb.poll_next_response());
for (int i = 0; i < reqs.length; i++)
{
try
{
Request a = orb.get_next_response();
served.clear(a.result().value().extract_long());
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
// Check the acceleration factor.
long done_in = System.currentTimeMillis() - started;
long required = 0;
for (int i = 0; i < times.length; i++)
{
required += times [ i ];
}
// Compute the acceleration factor * 100 %.
int acceleration = (int) ((100 * required) / done_in);
// With 20 virtual servers and the used algorithm, we should
// expect at least five-fold acceleration.
assertTrue("Parallel work is broken :" + acceleration, acceleration > 500);
assertEquals("Not all tasks served", served.cardinality(), 0);
// 2. Testing the Request methods.
Request rq =
objects [ 0 ]._create_request(null, "sleep_and_return",
orb.create_list(1), null
);
rq.set_return_type(orb.get_primitive_tc(TCKind.tk_long));
rq.add_in_arg().insert_long(200);
long t = System.currentTimeMillis();
rq.send_deferred();
// Be sure the execution has returned correctly.
assertTrue("Hangs on Request.send_defferred",
System.currentTimeMillis() < t + 199
);
assertTrue("Request.send_defferred:cannot be ready immediately",
!rq.poll_response());
try
{
Thread.sleep(300);
}
catch (InterruptedException ex)
{
}
assertTrue("Request.send_defferred:Must be ready now",
rq.poll_response());
assertEquals("Request.send_defferred:Result must be ready",
rq.result().value().extract_long(), 200);
orb.shutdown(true);
}