Search in sources :

Example 6 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException in project edge-cloud-sampleapps by mobiledgex.

the class EngineCallTest method getQosPositionKpiTest.

@Test
public void getQosPositionKpiTest() {
    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);
    ChannelIterator<AppClient.QosPositionKpiReply> responseIterator = null;
    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());
        if (useHostOverride) {
            responseIterator = me.getQosPositionKpi(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            responseIterator = me.getQosPositionKpi(request, GRPC_TIMEOUT_MS);
        }
        // A stream of QosPositionKpiReply(s), with a non-stream block of responses.
        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("queryQosKpiTest: DmeDnsException!", true);
    } catch (ExecutionException ee) {
        Log.i(TAG, Log.getStackTraceString(ee));
        assertFalse("queryQosKpiTest: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.i(TAG, sre.getMessage());
        Log.i(TAG, Log.getStackTraceString(sre));
        assertFalse("queryQosKpiTest: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.i(TAG, Log.getStackTraceString(ie));
        assertFalse("queryQosKpiTest: InterruptedException!", true);
    } finally {
        enableMockLocation(context, false);
        if (responseIterator != null) {
            responseIterator.shutdown();
        }
    }
}
Also used : Context(android.content.Context) 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)

Example 7 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException in project edge-cloud-sampleapps by mobiledgex.

the class EngineCallTest method registerClient.

// Every call needs registration to be called first at some point.
public void registerClient(MatchingEngine me) {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    AppClient.RegisterClientReply registerReply;
    AppClient.RegisterClientRequest regRequest;
    try {
        // The app version will be null, but we can build from scratch for test
        List<Pair<String, Long>> ids = me.retrieveCellId(context);
        AppClient.RegisterClientRequest.Builder regRequestBuilder = AppClient.RegisterClientRequest.newBuilder().setOrgName(organizationName).setAppName(applicationName).setAppVers(appVersion);
        if (ids != null && ids.size() > 0) {
            regRequestBuilder.setCellId(me.retrieveCellId(context).get(0).second.intValue());
        }
        regRequest = regRequestBuilder.build();
        if (useHostOverride) {
            registerReply = me.registerClient(regRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            registerReply = me.registerClient(regRequest, GRPC_TIMEOUT_MS);
        }
    // TODO: Validate JWT
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertTrue("ExecutionException registering client.", false);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertTrue("ExecutionException registering client", false);
    } catch (InterruptedException ioe) {
        Log.e(TAG, Log.getStackTraceString(ioe));
        assertTrue("InterruptedException registering client", false);
    }
}
Also used : Context(android.content.Context) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Pair(android.util.Pair) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException)

Example 8 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException in project edge-cloud-sampleapps by mobiledgex.

the class EngineCallTest method testWiFiOnly.

// Mini test of wifi only:
@Test
public void testWiFiOnly() {
    useWifiOnly = true;
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    assertEquals(true, me.isUseWifiOnly());
    String overrideHost = "";
    try {
        overrideHost = me.generateDmeHostAddress();
    } catch (DmeDnsException dde) {
        assertTrue("Cannot set to use WiFi! DNS failure!", false);
    }
    assertEquals(me.wifiOnlyDmeHost, overrideHost);
    me.setUseWifiOnly(useWifiOnly = false);
    assertEquals(false, me.isUseWifiOnly());
}
Also used : Context(android.content.Context) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 9 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException in project edge-cloud-sampleapps by mobiledgex.

the class EngineCallTest method verifyLocationTest.

@Test
public void verifyLocationTest() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.VerifyLocationReply verifyLocationReply = null;
    try {
        enableMockLocation(context, true);
        Location mockLoc = MockUtils.createLocation("verifyLocationTest", -96.994, 32.4824);
        setMockLocation(context, mockLoc);
        Location location = getTestLocation(-96.994, 32.4824);
        String carrierName = me.retrieveNetworkCarrierName(context);
        registerClient(me);
        AppClient.VerifyLocationRequest verifyLocationRequest = me.createDefaultVerifyLocationRequest(context, location).setCarrierName(carrierName).build();
        if (useHostOverride) {
            verifyLocationReply = me.verifyLocation(verifyLocationRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            verifyLocationReply = me.verifyLocation(verifyLocationRequest, GRPC_TIMEOUT_MS);
        }
        assert (verifyLocationReply != null);
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("VerifyLocation: DmeDnsException", true);
    } catch (IOException ioe) {
        Log.e(TAG, Log.getStackTraceString(ioe));
        assertFalse("VerifyLocation: IOException!", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("VerifyLocation: ExecutionExecution!", true);
    } catch (StatusRuntimeException sre) {
        Log.e(TAG, Log.getStackTraceString(sre));
        assertFalse("VerifyLocation: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("VerifyLocation: InterruptedException!", true);
    } finally {
        enableMockLocation(context, false);
    }
    // Temporary.
    assertEquals(0, verifyLocationReply.getVer());
    assertEquals(AppClient.VerifyLocationReply.TowerStatus.TOWER_UNKNOWN, verifyLocationReply.getTowerStatus());
    assertEquals(AppClient.VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MATCH, verifyLocationReply.getGpsLocationStatus());
}
Also used : Context(android.content.Context) StatusRuntimeException(io.grpc.StatusRuntimeException) AppClient(distributed_match_engine.AppClient) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 10 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException in project edge-cloud-sampleapps by mobiledgex.

the class EngineCallTest method getAppInstListTest.

@Test
public void getAppInstListTest() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.AppInstListReply appInstListReply = null;
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        registerClient(me);
        AppClient.AppInstListRequest appInstListRequest;
        AppClient.AppInstListReply list;
        appInstListRequest = me.createDefaultAppInstListRequest(context, location).setCarrierName(findCloudletCarrierOverride).build();
        if (useHostOverride) {
            list = me.getAppInstList(appInstListRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            list = me.getAppInstList(appInstListRequest, GRPC_TIMEOUT_MS);
        }
        assertEquals(0, list.getVer());
        assertEquals(AppClient.AppInstListReply.AIStatus.AI_SUCCESS, list.getStatus());
        // NOTE: This is entirely test server dependent.
        assertEquals(3, list.getCloudletsCount());
        for (int i = 0; i < list.getCloudletsCount(); i++) {
            Log.v(TAG, "Cloudlet: " + list.getCloudlets(i).toString());
        }
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("getAppInstListTest: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.i(TAG, Log.getStackTraceString(ee));
        assertFalse("getAppInstListTest: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.i(TAG, Log.getStackTraceString(sre));
        Log.i(TAG, sre.getMessage());
        assertFalse("getAppInstListTest: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.i(TAG, Log.getStackTraceString(ie));
        assertFalse("getAppInstListTest: InterruptedException!", true);
    }
}
Also used : Context(android.content.Context) StatusRuntimeException(io.grpc.StatusRuntimeException) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Aggregations

DmeDnsException (com.mobiledgex.matchingengine.DmeDnsException)30 AppClient (distributed_match_engine.AppClient)29 ExecutionException (java.util.concurrent.ExecutionException)29 Context (android.content.Context)27 MatchingEngine (com.mobiledgex.matchingengine.MatchingEngine)27 Test (org.junit.Test)25 Location (android.location.Location)23 StatusRuntimeException (io.grpc.StatusRuntimeException)16 PackageManager (android.content.pm.PackageManager)13 IOException (java.io.IOException)7 AppConnectionManager (com.mobiledgex.matchingengine.AppConnectionManager)4 OkHttpClient (com.squareup.okhttp.OkHttpClient)3 Request (com.squareup.okhttp.Request)3 Response (com.squareup.okhttp.Response)3 Appcommon (distributed_match_engine.Appcommon)3 AppPort (distributed_match_engine.Appcommon.AppPort)3 Pair (android.util.Pair)2 MediaType (com.squareup.okhttp.MediaType)2 RequestBody (com.squareup.okhttp.RequestBody)2 Socket (java.net.Socket)2