Search in sources :

Example 1 with ChannelIterator

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);
    }
}
Also used : Context(android.content.Context) ChannelIterator(com.mobiledgex.matchingengine.ChannelIterator) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) StatusRuntimeException(io.grpc.StatusRuntimeException) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Aggregations

Context (android.content.Context)1 Location (android.location.Location)1 ChannelIterator (com.mobiledgex.matchingengine.ChannelIterator)1 DmeDnsException (com.mobiledgex.matchingengine.DmeDnsException)1 MatchingEngine (com.mobiledgex.matchingengine.MatchingEngine)1 AppClient (distributed_match_engine.AppClient)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1