Search in sources :

Example 1 with DmeDnsException

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

the class ComputerVisionRestUnitTest method registerAndFindCloudlet.

/*
     * Return url of MobiledgeXSDK Demo backend
     */
private String registerAndFindCloudlet(Context ctx) {
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        AppClient.RegisterClientRequest registerRequest = me.createDefaultRegisterClientRequest(ctx, orgName).setAppName(appName).setAppVers(appVers).build();
        AppClient.RegisterClientReply registerReply = me.registerClient(registerRequest, GRPC_TIMEOUT_MS);
        Thread.sleep(4000);
        if (registerReply == null) {
            Log.e(TAG, "Register Client reply is null");
            return null;
        }
        if (registerReply.getStatus() != AppClient.ReplyStatus.RS_SUCCESS) {
            Log.e(TAG, "Register Client reply status is " + registerReply.getStatus());
            return null;
        }
        Location location = new Location("MobiledgeX_Loc_Sim");
        location.setLatitude(latitude);
        location.setLongitude(longitude);
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(ctx, location).build();
        AppClient.FindCloudletReply findCloudletReply = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        if (findCloudletReply == null) {
            Log.e(TAG, "Find Cloudlet reply is null");
            return null;
        }
        if (findCloudletReply.getStatus() != AppClient.FindCloudletReply.FindStatus.FIND_FOUND) {
            Log.e(TAG, "Find Cloudlet find status is " + findCloudletReply.getStatus());
            return null;
        }
        String fqdn = findCloudletReply.getFqdn();
        Appcommon.AppPort appPort = findCloudletReply.getPorts(0);
        int publicPort = appPort.getPublicPort();
        String fqdnPrefix = appPort.getFqdnPrefix();
        return "http://" + fqdnPrefix + fqdn + ":" + publicPort;
    } catch (DmeDnsException dde) {
        Log.e(TAG, "ExecutionException registering client. " + dde.getMessage());
        return null;
    } catch (ExecutionException ee) {
        Log.e(TAG, "ExecutionException registering client. " + ee.getMessage());
        return null;
    } catch (InterruptedException ie) {
        Log.e(TAG, "InterruptedException registering client. " + ie.getMessage());
        return null;
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, "InterruptedException registering client. " + nnfe.getMessage());
        return null;
    }
}
Also used : MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Appcommon(distributed_match_engine.Appcommon) PackageManager(android.content.pm.PackageManager) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException)

Example 2 with DmeDnsException

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

the class MatchingEngineUnitTest method testFindCloudletPerformance.

@Test
public void testFindCloudletPerformance() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    Location location = new Location("MobiledgeX_Loc_Sim");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    try {
        AppClient.FindCloudletRequest request = me.createDefaultFindCloudletRequest(ctx, location).build();
        AppClient.FindCloudletReply reply = me.findCloudlet(request, GRPC_TIMEOUT_MS, MatchingEngine.FindCloudletMode.PERFORMANCE);
        assertTrue("Unable to get FindCloudletReply", reply != null);
        assertEquals("FindCloudlet status is " + reply.getStatus(), AppClient.FindCloudletReply.FindStatus.FIND_FOUND, reply.getStatus());
        assertTrue("Fqdn in FindCloudletReply is " + reply.getFqdn(), reply.getFqdn() != null && reply.getFqdn() != "");
        Log.i(TAG, "cloudlet location=" + reply.getCloudletLocation().getLatitude() + "," + reply.getCloudletLocation().getLongitude());
        assertNotEquals("Latitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLatitude());
        assertNotEquals("Longitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLongitude());
    } catch (DmeDnsException dde) {
        assertTrue("ExecutionException finding cloudlet. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException finding cloudlet. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException finding cloudlet. " + ie.getMessage(), false);
    }
}
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 3 with DmeDnsException

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

the class MatchingEngineUnitTest method testGetAppInstList.

@Test
public void testGetAppInstList() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    Location location = new Location("MobiledgeX_Loc_Sim");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    try {
        AppClient.AppInstListRequest request = me.createDefaultAppInstListRequest(ctx, location).build();
        AppClient.AppInstListReply reply = me.getAppInstList(request, GRPC_TIMEOUT_MS);
        assertTrue("Unable to get AppInstListReply", reply != null);
        assertEquals("AppInstListReply status is " + reply.getStatus(), AppClient.AppInstListReply.AIStatus.AI_SUCCESS, reply.getStatus());
    } catch (DmeDnsException dde) {
        assertTrue("ExecutionException getting app inst list. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException getting app inst list. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException getting app inst list. " + ie.getMessage(), false);
    }
}
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 4 with DmeDnsException

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

the class MatchingEngineUnitTest method testFindCloudlet.

@Test
public void testFindCloudlet() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    Location location = new Location("MobiledgeX_Loc_Sim");
    location.setLatitude(latitude);
    location.setLongitude(longitude);
    try {
        AppClient.FindCloudletRequest request = me.createDefaultFindCloudletRequest(ctx, location).build();
        AppClient.FindCloudletReply reply = me.findCloudlet(request, GRPC_TIMEOUT_MS);
        assertTrue("Unable to get FindCloudletReply", reply != null);
        assertEquals("FindCloudlet status is " + reply.getStatus(), AppClient.FindCloudletReply.FindStatus.FIND_FOUND, reply.getStatus());
        assertTrue("Fqdn in FindCloudletReply is " + reply.getFqdn(), reply.getFqdn() != null && reply.getFqdn() != "");
        Log.i(TAG, "cloudlet location=" + reply.getCloudletLocation().getLatitude() + "," + reply.getCloudletLocation().getLongitude());
        assertNotEquals("Latitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLatitude());
        assertNotEquals("Longitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLongitude());
    } catch (DmeDnsException dde) {
        assertTrue("ExecutionException finding cloudlet. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException finding cloudlet. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException finding cloudlet. " + ie.getMessage(), false);
    }
}
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 5 with DmeDnsException

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

the class EngineCallTest method getAppInstListFutureTest.

@Test
public void getAppInstListFutureTest() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        registerClient(me);
        AppClient.AppInstListRequest appInstListRequest = me.createDefaultAppInstListRequest(context, location).setCarrierName(findCloudletCarrierOverride).build();
        Future<AppClient.AppInstListReply> listFuture;
        if (useHostOverride) {
            listFuture = me.getAppInstListFuture(appInstListRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            listFuture = me.getAppInstListFuture(appInstListRequest, GRPC_TIMEOUT_MS);
        }
        AppClient.AppInstListReply list = listFuture.get();
        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("getAppInstListFutureTest: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.i(TAG, Log.getStackTraceString(ee));
        assertFalse("getAppInstListFutureTest: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.i(TAG, sre.getMessage());
        Log.i(TAG, Log.getStackTraceString(sre));
        assertFalse("getAppInstListFutureTest: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.i(TAG, Log.getStackTraceString(ie));
        assertFalse("getAppInstListFutureTest: InterruptedException!", true);
    }
}
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)

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