Search in sources :

Example 26 with DmeDnsException

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

the class FindCloudletTest method findCloudletBadCarrier.

@Test
public void findCloudletBadCarrier() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    AppClient.FindCloudletReply findCloudletReply1 = null;
    AppClient.FindCloudletReply findCloudletReply2 = null;
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        String carrierName = me.retrieveNetworkCarrierName(context);
        registerClient(me);
        // Set orgName and location, then override the rest for testing:
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(context, location).setCarrierName("Leon's Fly-by-night Carrier").build();
        if (useHostOverride) {
            findCloudletReply1 = me.findCloudlet(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            findCloudletReply1 = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        }
        // Second try:
        me.setThreadedPerformanceTest(true);
        if (useHostOverride) {
            findCloudletReply2 = me.findCloudlet(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            findCloudletReply2 = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        }
    } 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) {
        Log.e(TAG, sre.getMessage());
        Log.e(TAG, Log.getStackTraceString(sre));
        assertFalse("FindCloudlet: 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: PackageManager.NameNotFoundException!", true);
    }
    Log.i(TAG, "findCloudletReply1=" + findCloudletReply1);
    Log.i(TAG, "findCloudletReply2=" + findCloudletReply2);
    assertNotNull("FindCloudletReply1 is null!", findCloudletReply1);
    assertNotNull("FindCloudletReply2 is null!", findCloudletReply2);
    assertEquals("status doesn't match", AppClient.FindCloudletReply.FindStatus.FIND_NOTFOUND, findCloudletReply1.getStatus());
}
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)

Example 27 with DmeDnsException

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

the class FindCloudletTest method findCloudletFutureTest.

@Test
public void findCloudletFutureTest() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    Future<AppClient.FindCloudletReply> response;
    AppClient.FindCloudletReply findCloudletReply1 = null;
    AppClient.FindCloudletReply findCloudletReply2 = null;
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    try {
        Location location = getTestLocation(47.6062, 122.3321);
        registerClient(me);
        // Cannot use the older API if overriding.
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(context, location).setCarrierName(findCloudletCarrierOverride).build();
        if (useHostOverride) {
            response = me.findCloudletFuture(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            response = me.findCloudletFuture(findCloudletRequest, 10000);
        }
        findCloudletReply1 = response.get();
        // Second try:
        me.setThreadedPerformanceTest(true);
        if (useHostOverride) {
            response = me.findCloudletFuture(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            response = me.findCloudletFuture(findCloudletRequest, GRPC_TIMEOUT_MS);
        }
        findCloudletReply2 = response.get();
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("FindCloudletFuture: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("FindCloudletFuture: ExecutionExecution!", true);
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("FindCloudletFuture: InterruptedException!", true);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, Log.getStackTraceString(nnfe));
        assertFalse("FindCloudletFuture: PackageManager.NameNotFoundException!", true);
    } finally {
        enableMockLocation(context, false);
    }
    assertNotNull("FindCloudletReply1 is null!", findCloudletReply1);
    assertNotNull("FindCloudletReply2 is null!", findCloudletReply2);
    assertEquals(findCloudletReply1.getFqdn(), findCloudletReply2.getFqdn());
    // Might also fail, since the network is not under test control:
    assertEquals("App's expected test cloudlet FQDN doesn't match.", "sdkdemo-app-cluster.dusseldorf-main.tdg.mobiledgex.net", findCloudletReply1.getFqdn());
}
Also used : Context(android.content.Context) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) PackageManager(android.content.pm.PackageManager) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Location(android.location.Location) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 28 with DmeDnsException

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

the class RegisterClientTest method registerClientBadAppVersion.

@Test
public void registerClientBadAppVersion() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.RegisterClientReply reply = null;
    try {
        AppClient.RegisterClientRequest request = me.createDefaultRegisterClientRequest(context, organizationName).setAppName(applicationName).setAppVers("-999").setCellId(getCellId(context, me)).build();
        if (useHostOverride) {
            reply = me.registerClient(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            reply = me.registerClient(request, me.generateDmeHostAddress(), me.getPort(), GRPC_TIMEOUT_MS);
        }
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, Log.getStackTraceString(nnfe));
        assertFalse("ExecutionException registering using PackageManager.", true);
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("registerClientTest: DmeDnsException!", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("registerClientTest: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.e(TAG, Log.getStackTraceString(sre));
        // This is expected when appVersion is wrong.
        assertEquals("NOT_FOUND: app not found", sre.getLocalizedMessage());
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("registerClientTest: InterruptedException!", true);
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) StatusRuntimeException(io.grpc.StatusRuntimeException) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 29 with DmeDnsException

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

the class RegisterClientTest method registerClientEmptyAppVersion.

@Test
public void registerClientEmptyAppVersion() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.RegisterClientReply reply = null;
    try {
        AppClient.RegisterClientRequest request = me.createDefaultRegisterClientRequest(context, organizationName).setAppName(applicationName).setAppVers("").setCellId(getCellId(context, me)).build();
        if (useHostOverride) {
            reply = me.registerClient(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            reply = me.registerClient(request, me.generateDmeHostAddress(), me.getPort(), GRPC_TIMEOUT_MS);
        }
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.e(TAG, Log.getStackTraceString(nnfe));
        assertFalse("ExecutionException registering using PackageManager.", true);
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("registerClientTest: DmeDnsException!", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("registerClientTest: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.e(TAG, Log.getStackTraceString(sre));
        // This is expected when AppVers is empty.
        assertEquals("INVALID_ARGUMENT: AppVers cannot be empty", sre.getLocalizedMessage());
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("registerClientTest: InterruptedException!", true);
    }
}
Also used : Context(android.content.Context) PackageManager(android.content.pm.PackageManager) StatusRuntimeException(io.grpc.StatusRuntimeException) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 30 with DmeDnsException

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

the class FaceProcessorActivity method exampleDeveloperWorkflow.

public Socket exampleDeveloperWorkflow() {
    MatchingEngine me = new MatchingEngine(this);
    AppConnectionManager appConnect = me.getAppConnectionManager();
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    String host = null;
    try {
        host = me.generateDmeHostAddress();
    } catch (DmeDnsException e) {
        e.printStackTrace();
    }
    if (host == null) {
        Log.e(TAG, "Could not generate host");
        // fallback host
        host = "wifi.dme.mobiledgex.net";
    }
    // Keep same port.
    int port = me.getPort();
    String appName = "ComputerVision";
    String appVersion = "2.2";
    String orgName = "MobiledgeX-Samples";
    Location location = new Location("MobiledgeX");
    location.setLatitude(52.52);
    // Berlin
    location.setLongitude(13.4040);
    Future<AppClient.FindCloudletReply> future = me.registerAndFindCloudlet(this, host, port, orgName, appName, appVersion, location, "", 0, "", "", null, MatchingEngine.FindCloudletMode.PROXIMITY);
    AppClient.FindCloudletReply findCloudletReply;
    try {
        findCloudletReply = future.get();
    } catch (ExecutionException | InterruptedException e) {
        e.printStackTrace();
        Log.e(TAG, "RegisterAndFindCloudlet error " + e.getMessage());
        return null;
    }
    HashMap<Integer, Appcommon.AppPort> portMap = appConnect.getTCPMap(findCloudletReply);
    // 8011 for persistent tcp
    Appcommon.AppPort one = portMap.get(8008);
    me.setNetworkSwitchingEnabled(true);
    Future<Socket> fs = appConnect.getTcpSocket(findCloudletReply, one, one.getPublicPort(), 15000);
    // if using wifi only
    me.setNetworkSwitchingEnabled(false);
    if (fs == null) {
        Log.e(TAG, "Socket future didn't return anything");
        return null;
    }
    Socket socket;
    try {
        socket = fs.get();
    } catch (ExecutionException | InterruptedException e) {
        Log.e(TAG, "Cannot get socket from future. Exception: " + e.getMessage());
        Toast.makeText(this, "Unable to connect. " + e.getMessage(), Toast.LENGTH_LONG);
        return null;
    }
    return socket;
}
Also used : MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) Appcommon(distributed_match_engine.Appcommon) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) Socket(java.net.Socket) AppConnectionManager(com.mobiledgex.matchingengine.AppConnectionManager) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Location(android.location.Location)

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