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