Search in sources :

Example 16 with DmeDnsException

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

the class MatchingEngineUnitTest method testGetQosPositionKpi.

@Test
public void testGetQosPositionKpi() {
    Context ctx = getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(ctx);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    registerClient(me, ctx);
    LocOuterClass.Loc loc = LocOuterClass.Loc.newBuilder().setLongitude(latitude).setLatitude(longitude).build();
    List<AppClient.QosPosition> qosPositions = generateQosPositionList(loc, 45, 200, 1);
    try {
        AppClient.QosPositionRequest request = me.createDefaultQosPositionRequest(qosPositions, lteCategory, bandSelection).build();
        ChannelIterator<AppClient.QosPositionKpiReply> responseIterator = me.getQosPositionKpi(request, GRPC_TIMEOUT_MS);
        assertTrue("No QosPositionKpi reply", responseIterator.hasNext());
        while (responseIterator.hasNext()) {
            AppClient.QosPositionKpiReply reply = responseIterator.next();
            AppClient.ReplyStatus status = reply.getStatus();
            assertEquals("QosPositionKpi reply status is " + status, AppClient.ReplyStatus.RS_SUCCESS, status);
        }
    } 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) LocOuterClass(distributed_match_engine.LocOuterClass) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) AppClient(distributed_match_engine.AppClient) ExecutionException(java.util.concurrent.ExecutionException) DmeDnsException(com.mobiledgex.matchingengine.DmeDnsException) Test(org.junit.Test)

Example 17 with DmeDnsException

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

the class MatchingEngineUnitTest method testVerifyLocation.

@Test
public void testVerifyLocation() {
    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.VerifyLocationRequest request = me.createDefaultVerifyLocationRequest(ctx, location).build();
        AppClient.VerifyLocationReply reply = me.verifyLocation(request, GRPC_TIMEOUT_MS);
        assertTrue("Unable to get VerifyLocation", reply != null);
        assertEquals("VerifyLocation Tower status is " + reply.getTowerStatus(), AppClient.VerifyLocationReply.TowerStatus.CONNECTED_TO_SPECIFIED_TOWER, reply.getTowerStatus());
        assertEquals("VerifyLocation GPS Location status is " + reply.getGpsLocationStatus(), AppClient.VerifyLocationReply.GPSLocationStatus.LOC_VERIFIED, reply.getGpsLocationStatus());
    } catch (DmeDnsException dde) {
        assertTrue("DmeDnsException verifying location. " + dde.getMessage(), false);
    } catch (ExecutionException ee) {
        assertTrue("ExecutionException verifying location. " + ee.getMessage(), false);
    } catch (InterruptedException ie) {
        assertTrue("InterruptedException verifying location. " + ie.getMessage(), false);
    } catch (IOException ioe) {
        assertTrue("IOException verifying location. " + ioe.getMessage(), false);
    }
}
Also used : Context(android.content.Context) 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 18 with DmeDnsException

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

the class EngineCallTest method verifyMockedLocationTest_NorthPole.

/**
 * Mocked Location test. Note that responsibility of verifying location is in the MatchingEngine
 * on the server side, not client side.
 */
@Test
public void verifyMockedLocationTest_NorthPole() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    enableMockLocation(context, true);
    Location mockLoc = MockUtils.createLocation("verifyMockedLocationTest_NorthPole", 90d, 1d);
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    AppClient.VerifyLocationReply verifyLocationReply = 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) {
            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("verifyMockedLocationTest_NorthPole: DmeDnsException", true);
    } catch (IOException ioe) {
        Log.e(TAG, Log.getStackTraceString(ioe));
        assertFalse("verifyMockedLocationTest_NorthPole: IOException!", true);
    } catch (ExecutionException ee) {
        Log.e(TAG, Log.getStackTraceString(ee));
        assertFalse("verifyMockedLocationTest_NorthPole: ExecutionException!", true);
    } catch (InterruptedException ie) {
        Log.e(TAG, Log.getStackTraceString(ie));
        assertFalse("verifyMockedLocationTest_NorthPole: InterruptedException!", true);
    }
    // Temporary.
    assertEquals(0, verifyLocationReply.getVer());
    assertEquals(AppClient.VerifyLocationReply.TowerStatus.TOWER_UNKNOWN, verifyLocationReply.getTowerStatus());
    // Based on test data.
    assertEquals(AppClient.VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MATCH, verifyLocationReply.getGpsLocationStatus());
}
Also used : Context(android.content.Context) 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 19 with DmeDnsException

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

the class EngineCallTest method appConnectionTestTcp002.

/**
 * Tests the MatchingEngine SDK supplied HTTP connection to the edge cloudlet. FIXME: TLS Test with certs.
 */
@Test
public void appConnectionTestTcp002() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    AppConnectionManager appConnect = me.getAppConnectionManager();
    me.setMatchingEngineLocationAllowed(true);
    me.setAllowSwitchIfNoSubscriberInfo(true);
    OkHttpClient httpClient = null;
    // Test against Http Echo.
    String carrierName = "TDG";
    String appName = "HttpEcho";
    String orgName = "MobiledgeX";
    String appVersion = "20191204";
    try {
        String data = "{\"Data\": \"food\"}";
        AppClient.RegisterClientRequest req = me.createDefaultRegisterClientRequest(context, orgName).setCarrierName(carrierName).setAppName(appName).setAppVers(appVersion).build();
        AppClient.RegisterClientReply registerReply;
        // FIXME: Need/want a secondary cloudlet for this AppInst test.
        if (true) {
            registerReply = me.registerClient(req, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            registerReply = me.registerClient(req, GRPC_TIMEOUT_MS);
        }
        assertTrue("Register did not succeed for HttpEcho appInst", registerReply.getStatus() == AppClient.ReplyStatus.RS_SUCCESS);
        Location location = getTestLocation(47.6062, 122.3321);
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(context, location).setCarrierName(carrierName).build();
        assertEquals("Session cookies don't match!", registerReply.getSessionCookie(), findCloudletRequest.getSessionCookie());
        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((int) GRPC_TIMEOUT_MS);
        // FIXME: UI Console exposes HTTP as TCP only, so test here use getTcpMap().
        String url = null;
        assertTrue("No AppPorts!", findCloudletReply.getPortsCount() > 0);
        HashMap<Integer, AppPort> portMap = appConnect.getTCPMap(findCloudletReply);
        // Choose the port that we happen to know the internal port for, 3001.
        AppPort one = portMap.get(3001);
        url = appConnect.createUrl(findCloudletReply, one, one.getPublicPort());
        assertTrue("URL for server seems very incorrect. ", url != null && url.length() > "http://:".length());
        assertFalse("Failed to get an SSL Socket!", httpClientFuture == null);
        // Interface bound TCP socket, has default timeout equal to NetworkManager.
        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);
    } catch (PackageManager.NameNotFoundException nnfe) {
    } catch (IOException ioe) {
        Log.e(TAG, Log.getStackTraceString(ioe));
        assertFalse("appConnectionTestTcp002: IOException", true);
    } catch (DmeDnsException dde) {
        Log.e(TAG, Log.getStackTraceString(dde));
        assertFalse("appConnectionTestTcp002: DmeDnsException", true);
    } catch (ExecutionException ee) {
        Log.i(TAG, Log.getStackTraceString(ee));
        assertFalse("appConnectionTestTcp002: ExecutionException!", true);
    } catch (StatusRuntimeException sre) {
        Log.i(TAG, sre.getMessage());
        Log.i(TAG, Log.getStackTraceString(sre));
        assertFalse("appConnectionTestTcp002: StatusRuntimeException!", true);
    } catch (InterruptedException ie) {
        Log.i(TAG, Log.getStackTraceString(ie));
        assertFalse("appConnectionTestTcp002: InterruptedException!", true);
    } finally {
        enableMockLocation(context, false);
    }
}
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) 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 20 with DmeDnsException

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

the class EngineCallTest method appConnectionTestTcp001.

/**
 * Tests the MatchingEngine SDK supplied TCP connection to the edge cloudlet.
 *
 * This is a raw stream to a test echo server, so there are no explicit message delimiters.
 */
@Test
public void appConnectionTestTcp001() {
    Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
    MatchingEngine me = new MatchingEngine(context);
    me.setUseWifiOnly(useWifiOnly);
    AppConnectionManager appConnect = me.getAppConnectionManager();
    enableMockLocation(context, true);
    Socket s = null;
    BufferedOutputStream bos = null;
    BufferedInputStream bis = null;
    try {
        // Test against Http Echo.
        String carrierName = "TDG";
        String appName = "HttpEcho";
        String orgName = "MobiledgeX";
        String appVersion = "20191204";
        // Exercise and override the default:
        // The app version will be null, but we can build from scratch for test
        AppClient.RegisterClientRequest regRequest = AppClient.RegisterClientRequest.newBuilder().setCarrierName(me.retrieveNetworkCarrierName(context)).setOrgName(orgName).setAppName(appName).setAppVers(appVersion).build();
        AppClient.RegisterClientReply registerClientReply;
        if (true) {
            registerClientReply = me.registerClient(regRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            registerClientReply = me.registerClient(regRequest, GRPC_TIMEOUT_MS);
        }
        assertTrue("Register did not succeed for HttpEcho appInst", registerClientReply.getStatus() == AppClient.ReplyStatus.RS_SUCCESS);
        Location location = getTestLocation(47.6062, 122.3321);
        // Defaults:
        AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(context, location).setCarrierName(findCloudletCarrierOverride).build();
        AppClient.FindCloudletReply findCloudletReply;
        if (true) {
            findCloudletReply = me.findCloudlet(findCloudletRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
        } else {
            findCloudletReply = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
        }
        // Just using first one. This depends entirely on the server design.
        List<AppPort> appPorts = findCloudletReply.getPortsList();
        assertTrue("AppPorts is null", appPorts != null);
        assertTrue("AppPorts is empty!", appPorts.size() > 0);
        HashMap<Integer, AppPort> portMap = appConnect.getTCPMap(findCloudletReply);
        // This internal port depends entirely the AppInst configuration/Docker image.
        AppPort one = portMap.get(3001);
        assertTrue("EndPort is expected to be 0 for this AppInst", one.getEndPort() == 0);
        // The actual mapped Public port, or one between getPublicPort() to getEndPort(), inclusive.
        Future<Socket> fs = appConnect.getTcpSocket(findCloudletReply, one, one.getPublicPort(), (int) GRPC_TIMEOUT_MS);
        // Interface bound TCP socket.
        // Nothing to do. Await value.
        s = fs.get();
        try {
            bos = new BufferedOutputStream(s.getOutputStream());
            String data = "{\"Data\": \"food\"}";
            String rawpost = "POST / HTTP/1.1\r\n" + "Host: 10.227.66.62:3000\r\n" + "User-Agent: curl/7.54.0\r\n" + "Accept: */*\r\n" + "Content-Length: " + data.length() + "\r\n" + "Content-Type: application/json\r\n" + "\r\n" + data;
            bos.write(rawpost.getBytes());
            bos.flush();
            // Some arbitrary object Monitor.
            Object aMon = new Object();
            synchronized (aMon) {
                aMon.wait(1000);
            }
            bis = new BufferedInputStream(s.getInputStream());
            int available = bis.available();
            // Probably true.
            assertTrue("No bytes available in response.", available > 0);
            byte[] b = new byte[4096];
            int numRead = bis.read(b);
            assertTrue("Didn't get response!", numRead > 0);
            String output = new String(b);
            // Not an http client, so we're just going to get the substring of something stable:
            boolean found = output.indexOf("food") != -1 ? true : false;
            ;
            assertTrue("Didn't find json data [" + data + "] in response!", found == true);
        } catch (IOException ioe) {
            assertTrue("Failed to get output stream for socket!", false);
        }
    } 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.i(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);
    } catch (PackageManager.NameNotFoundException nnfe) {
        Log.i(TAG, Log.getStackTraceString(nnfe));
        assertFalse("appConnectionTestTcp001: NameNotFoundException!", true);
    } finally {
        try {
            if (bis != null) {
                bis.close();
            }
            if (bos != null) {
                bos.close();
            }
            if (s != null) {
                s.close();
            }
        } catch (IOException ioe) {
            assertFalse("IO Exceptions trying to close socket.", true);
        }
        me.setNetworkSwitchingEnabled(true);
    }
}
Also used : AppPort(distributed_match_engine.Appcommon.AppPort) PackageManager(android.content.pm.PackageManager) BufferedInputStream(java.io.BufferedInputStream) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) BufferedOutputStream(java.io.BufferedOutputStream) Context(android.content.Context) IOException(java.io.IOException) MatchingEngine(com.mobiledgex.matchingengine.MatchingEngine) AppClient(distributed_match_engine.AppClient) Socket(java.net.Socket) AppConnectionManager(com.mobiledgex.matchingengine.AppConnectionManager) 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