use of com.mobiledgex.matchingengine.ChannelIterator in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method getQosPositionKpiFutureTest.
@Test
public void getQosPositionKpiFutureTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
enableMockLocation(context, true);
// The test must use a location where data exists on QOS server.
Location location = MockUtils.createLocation("getQosPositionKpiTest", 8.5821, 50.11);
try {
registerClient(me);
double totalDistanceKm = 20;
double increment = 0.1;
double direction = 45d;
ArrayList<AppClient.QosPosition> kpiRequests = MockUtils.createQosPositionArray(location, direction, totalDistanceKm, increment);
AppClient.QosPositionRequest request = me.createQoSPositionRequest(kpiRequests, 0, null, 0, null);
assertFalse("SessionCookie must not be empty.", request.getSessionCookie().isEmpty());
Future<ChannelIterator<AppClient.QosPositionKpiReply>> replyFuture = null;
if (useHostOverride) {
replyFuture = me.getQosPositionKpiFuture(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
} else {
replyFuture = me.getQosPositionKpiFuture(request, GRPC_TIMEOUT_MS);
}
// A stream of QosPositionKpiReply(s), with a non-stream block of responses.
// Wait for value with get().
ChannelIterator<AppClient.QosPositionKpiReply> responseIterator = replyFuture.get();
long total = 0;
while (responseIterator.hasNext()) {
AppClient.QosPositionKpiReply aR = responseIterator.next();
for (int i = 0; i < aR.getPositionResultsCount(); i++) {
System.out.println(aR.getPositionResults(i));
}
total += aR.getPositionResultsCount();
}
responseIterator.shutdown();
assertEquals((long) (kpiRequests.size()), total);
} catch (DmeDnsException dde) {
Log.i(TAG, Log.getStackTraceString(dde));
assertFalse("getQosPositionKpiFutureTest: DmeDnsException!", true);
} catch (ExecutionException ee) {
Log.i(TAG, Log.getStackTraceString(ee));
assertFalse("getQosPositionKpiFutureTest: ExecutionException!", true);
} catch (StatusRuntimeException sre) {
Log.i(TAG, sre.getMessage());
Log.i(TAG, Log.getStackTraceString(sre));
assertFalse("getQosPositionKpiFutureTest: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.i(TAG, Log.getStackTraceString(ie));
assertFalse("getQosPositionKpiFutureTest: InterruptedException!", true);
} finally {
enableMockLocation(context, false);
}
}
Aggregations