Search in sources :

Example 21 with DmeDnsException

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

the class EngineCallTest method verifyLocationFutureTest.

@Test
public void verifyLocationFutureTest() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.VerifyLocationReply verifyLocationReply = null;
    Future<AppClient.VerifyLocationReply> verifyLocationReplyFuture = null;
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        String carrierName = me.retrieveNetworkCarrierName(context);
        registerClient(me);
        AppClient.VerifyLocationRequest verifyLocationRequest = me.createDefaultVerifyLocationRequest(context, location).setCarrierName(carrierName).build();
        if (useHostOverride) {
            verifyLocationReplyFuture = me.verifyLocationFuture(verifyLocationRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            verifyLocationReplyFuture = me.verifyLocationFuture(verifyLocationRequest, GRPC_TIMEOUT_MS);
        }
        verifyLocationReply = verifyLocationReplyFuture.get();
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("verifyLocationFutureTest: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("verifyLocationFutureTest: ExecutionException Failed!", true);
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("verifyLocationFutureTest: InterruptedException!", true);
    }
    // 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) 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)

Example 22 with DmeDnsException

use of com.mobiledgex.matchingengine.DmeDnsException 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)

Example 23 with DmeDnsException

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

the class EngineCallTest method appConnectionTestTcp_Http_001.

/**
 * NOTE: HttpEcho may only be installed on wifi.dme domain
 */
@Test
public void appConnectionTestTcp_Http_001() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    AppConnectionManager appConnect = me.getAppConnectionManager();
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        String data = "{\"Data\": \"food\"}";
        String carrierName = "TDG";
        String orgName = "MobiledgeX";
        String appName = "HttpEcho";
        String appVersion = "20191204";
        AppClient.RegisterClientRequest req = me.createDefaultRegisterClientRequest(context, orgName).setCarrierName(carrierName).setAppName(appName).setAppVers(appVersion).build();
        AppClient.RegisterClientReply registerClientReply;
        // FIXME: Need/want a secondary cloudlet for this AppInst test.
        if (true) {
            registerClientReply = me.registerClient(req, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            registerClientReply = me.registerClient(req, GRPC_TIMEOUT_MS);
        }
        assertTrue("Register did not succeed for HttpEcho appInst", registerClientReply.getStatus() == AppClient.ReplyStatus.RS_SUCCESS);
        Location location = getTestLocation(47.6062, 122.3321);
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(context, location).setCarrierName(carrierName).build();
        // TODO: Validate JWT
        AppClient.FindCloudletReply findCloudletReply;
        if (true) {
            findCloudletReply = me.findCloudlet(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            findCloudletReply = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        }
        // SSL:
        Future<OkHttpClient> httpClientFuture = null;
        httpClientFuture = appConnect.getHttpClient(GRPC_TIMEOUT_MS);
        assertTrue("HttpClientFuture is NULL!", httpClientFuture != null);
        // FIXME: UI Console exposes HTTP as TCP only, so the test here uses getTcpList().
        String url = null;
        HashMap<Integer, AppPort> portMap = appConnect.getTCPMap(findCloudletReply);
        // Choose the TCP port, and we happen to know our server is on one port only: 3001.
        AppPort one = portMap.get(3001);
        assertTrue("Did not find server! ", one != null);
        url = appConnect.createUrl(findCloudletReply, one, one.getPublicPort());
        assertTrue("URL for server seems very incorrect. ", url != null && url.length() > "http://:".length());
        // Interface bound TCP socket, has default timeout equal to NetworkManager.
        OkHttpClient httpClient = httpClientFuture.get();
        MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(JSON, data);
        Request request = new Request.Builder().url(url).post(body).build();
        Response response = httpClient.newCall(request).execute();
        String output = response.body().string();
        boolean found = output.indexOf("food") != -1 ? true : false;
        assertTrue("Didn't find json data [" + data + "] in response!", found == true);
        Request mobiledgeXSiteRequest = new Request.Builder().url("https://mobiledgex.com").build();
        Response mexSiteResponse = httpClient.newCall(mobiledgeXSiteRequest).execute();
        int httpStatus = mexSiteResponse.code();
        assertEquals("Did not reach our home site. Status: ", 200, httpStatus);
        // This certificate goes to artifactory.mobiledgex.net, it *should* fail, but "connect" with
        // HTTP Status 200 OK.
        boolean failedVerification = false;
        mobiledgeXSiteRequest = new Request.Builder().url("https://mobiledgex.net").build();
        try {
            mexSiteResponse = httpClient.newCall(mobiledgeXSiteRequest).execute();
        } catch (SSLPeerUnverifiedException e) {
            failedVerification = true;
            httpStatus = mexSiteResponse.code();
            assertEquals("Should fail SSL Host verification, but still be 200 OK. Status: ", 200, httpStatus);
        }
        assertTrue("Did not fail hostname SSL verification!", failedVerification);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, nnfe.getMessage());
        Log.i(TAG, Log.getStackTraceString(nnfe));
        assertFalse("appConnectionTestTcp001: Package Info is missing!", true);
    } catch (IOException ioe) {
        Log.e(TAG, Log.getStackTraceString(ioe));
        assertFalse("appConnectionTestTcp001: IOException", true);
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("appConnectionTestTcp001: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.i(TAG, Log.getStackTraceString(ee));
        assertFalse("appConnectionTestTcp001: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.e(TAG, sre.getMessage());
        Log.i(TAG, Log.getStackTraceString(sre));
        assertFalse("appConnectionTestTcp001: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.i(TAG, Log.getStackTraceString(ie));
        assertFalse("appConnectionTestTcp001: InterruptedException!", true);
    }
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) AppPort(distributed_match_engine.Appcommon.AppPort) PackageManager(android.content.pm.PackageManager) StatusRuntimeException(io.grpc.StatusRuntimeException) MediaType(com.squareup.okhttp.MediaType) ExecutionException(java.util.concurrent.ExecutionException) RequestBody(com.squareup.okhttp.RequestBody) Context(android.content.Context) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException) Request(com.squareup.okhttp.Request) IOException(java.io.IOException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Response(com.squareup.okhttp.Response) AppClient(distributed_match_engine.AppClient) AppConnectionManager(com.mobiledgex.matchingengine.AppConnectionManager) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 24 with DmeDnsException

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

the class FindCloudletTest 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).setCellId(getCellId(context, me));
        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 25 with DmeDnsException

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

the class FindCloudletTest method findCloudletTestSetCarrierNameAnyOverride.

// This test only tests "" any, and not subject to the global override.
@Test
public void findCloudletTestSetCarrierNameAnyOverride() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    AppClient.FindCloudletReply findCloudletReply = null;
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    boolean expectedExceptionHit = false;
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        String carrierName = me.retrieveNetworkCarrierName(context);
        registerClient(me);
        // Set NO carrier name, as if there's no SIM card. This should tell DME to return
        // any edge AppInst from any carrier, for this app, version, orgName keyset.
        AppClient.FindCloudletRequest findCloudletRequest2 = me.createDefaultFindCloudletRequest(context, location).setCarrierName("").build();
        if (useHostOverride) {
            findCloudletReply = me.findCloudlet(findCloudletRequest2, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            findCloudletReply = me.findCloudlet(findCloudletRequest2, GRPC_TIMEOUT_MS);
        }
        assertTrue(findCloudletReply != null);
        assertTrue(findCloudletReply.getStatus().equals(AppClient.FindCloudletReply.FindStatus.FIND_FOUND));
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("FindCloudlet: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("FindCloudlet: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        /* This is expected! */
        Log.e(TAG, sre.getMessage());
        Log.e(TAG, Log.getStackTraceString(sre));
        expectedExceptionHit = true;
        assertTrue("FindCloudlet: Expected StatusRunTimeException!", true);
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("FindCloudlet: InterruptedException!", true);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, Log.getStackTraceString(nnfe));
        assertFalse("FindCloudlet: NameNotFoundException!", true);
    }
    assertFalse("findCloudletTestSetAllOptionalDevAppNameVers: NO Expected StatusRunTimeException about 'NO PERMISSION'", expectedExceptionHit);
}
Also used : Context(android.content.Context) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) PackageManager(android.content.pm.PackageManager) 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

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