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;
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations