use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method getAppInstListTest.
@Test
public void getAppInstListTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
AppClient.AppInstListReply appInstListReply = null;
try {
Location location = getTestLocation(47.6062, 122.3321);
registerClient(me);
AppClient.AppInstListRequest appInstListRequest;
AppClient.AppInstListReply list;
appInstListRequest = me.createDefaultAppInstListRequest(context, location).setCarrierName(findCloudletCarrierOverride).build();
if (useHostOverride) {
list = me.getAppInstList(appInstListRequest, hostOverride, portOverride, GRPC_TIMEOUT_MS);
} else {
list = me.getAppInstList(appInstListRequest, GRPC_TIMEOUT_MS);
}
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("getAppInstListTest: DmeDnsException", true);
} catch (ExecutionException ee) {
Log.i(TAG, Log.getStackTraceString(ee));
assertFalse("getAppInstListTest: ExecutionException!", true);
} catch (StatusRuntimeException sre) {
Log.i(TAG, Log.getStackTraceString(sre));
Log.i(TAG, sre.getMessage());
assertFalse("getAppInstListTest: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.i(TAG, Log.getStackTraceString(ie));
assertFalse("getAppInstListTest: InterruptedException!", true);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class FindCloudletTest method findCloudletTest.
@Test
public void findCloudletTest() {
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(findCloudletCarrierOverride).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);
}
assertNotNull("FindCloudletReply1 is null!", findCloudletReply1);
assertNotNull("FindCloudletReply2 is null!", findCloudletReply2);
// 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());
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class RegisterClientTest method registerClientFutureTest.
@Test
public void registerClientFutureTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
Future<AppClient.RegisterClientReply> registerReplyFuture;
AppClient.RegisterClientReply reply = null;
try {
Location location = getTestLocation(47.6062, 122.3321);
AppClient.RegisterClientRequest request = me.createDefaultRegisterClientRequest(context, organizationName).setAppName(applicationName).setAppVers(appVersion).setCellId(getCellId(context, me)).setUniqueIdType("applicationInstallId").setUniqueId(me.getUniqueId(context)).build();
if (useHostOverride) {
registerReplyFuture = me.registerClientFuture(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
} else {
registerReplyFuture = me.registerClientFuture(request, GRPC_TIMEOUT_MS);
}
reply = registerReplyFuture.get();
assert (reply != null);
} 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("ExecutionException registering client.", true);
} catch (ExecutionException ee) {
Log.e(TAG, Log.getStackTraceString(ee));
assertFalse("registerClientFutureTest: ExecutionException!", true);
} catch (InterruptedException ie) {
Log.e(TAG, Log.getStackTraceString(ie));
assertFalse("registerClientFutureTest: InterruptedException!", true);
}
// TODO: Validate JWT
Log.i(TAG, "registerClientFutureTest() response: " + reply.toString());
assertEquals(0, reply.getVer());
assertEquals(AppClient.ReplyStatus.RS_SUCCESS, reply.getStatus());
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class RegisterClientTest method registerClientBadAppName.
@Test
public void registerClientBadAppName() {
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("Leon's Bogus App").setAppVers(appVersion).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 appName is wrong.
assertEquals("NOT_FOUND: app not found", sre.getLocalizedMessage());
} catch (InterruptedException ie) {
Log.e(TAG, Log.getStackTraceString(ie));
assertFalse("registerClientTest: InterruptedException!", true);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class RegisterClientTest method registerClientTest.
@Test
public void registerClientTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
AppClient.RegisterClientReply reply = null;
String appName = applicationName;
try {
Location location = getTestLocation(47.6062, 122.3321);
AppClient.RegisterClientRequest request = me.createDefaultRegisterClientRequest(context, organizationName).setAppName(applicationName).setAppVers(appVersion).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);
}
JWT jwt = null;
try {
jwt = new JWT(reply.getSessionCookie());
} catch (DecodeException e) {
Log.e(TAG, Log.getStackTraceString(e));
assertFalse("registerClientTest: DecodeException!", true);
}
// Validate JWT
// 10 seconds leeway
boolean isExpired = jwt.isExpired(10);
assertTrue(!isExpired);
Log.i(TAG, "Claims count: " + jwt.getClaims().keySet().size());
for (String key : jwt.getClaims().keySet()) {
Claim claim = jwt.getClaims().get(key);
Log.i(TAG, "key: " + key + " Claim: " + claim.asString());
}
Claim c = jwt.getClaim("key");
JsonObject claimJson = c.asObject(JsonObject.class);
String orgName = claimJson.get("orgname").getAsString();
assertEquals("orgname doesn't match!", "MobiledgeX", orgName);
Log.i(TAG, "registerReply.getSessionCookie()=" + reply.getSessionCookie());
assertTrue(reply != null);
assertTrue(reply.getStatus() == AppClient.ReplyStatus.RS_SUCCESS);
assertTrue(!reply.getUniqueId().isEmpty());
assertTrue(reply.getSessionCookie().length() > 0);
} 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));
assertFalse("registerClientTest: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.e(TAG, Log.getStackTraceString(ie));
assertFalse("registerClientTest: InterruptedException!", true);
}
Log.i(TAG, "registerClientTest reply: " + reply.toString());
assertEquals(0, reply.getVer());
assertEquals(AppClient.ReplyStatus.RS_SUCCESS, reply.getStatus());
}
Aggregations