use of com.mobiledgex.matchingengine.MatchingEngine 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.MatchingEngine 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);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method getQosPositionKpiTest.
@Test
public void getQosPositionKpiTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
enableMockLocation(context, true);
// The test must use a location where data exists on QOS server.
Location location = MockUtils.createLocation("getQosPositionKpiTest", 8.5821, 50.11);
ChannelIterator<AppClient.QosPositionKpiReply> responseIterator = null;
try {
registerClient(me);
double totalDistanceKm = 20;
double increment = 0.1;
double direction = 45d;
ArrayList<AppClient.QosPosition> kpiRequests = MockUtils.createQosPositionArray(location, direction, totalDistanceKm, increment);
AppClient.QosPositionRequest request = me.createQoSPositionRequest(kpiRequests, 0, null, 0, null);
assertFalse("SessionCookie must not be empty.", request.getSessionCookie().isEmpty());
if (useHostOverride) {
responseIterator = me.getQosPositionKpi(request, hostOverride, portOverride, GRPC_TIMEOUT_MS);
} else {
responseIterator = me.getQosPositionKpi(request, GRPC_TIMEOUT_MS);
}
// A stream of QosPositionKpiReply(s), with a non-stream block of responses.
long total = 0;
while (responseIterator.hasNext()) {
AppClient.QosPositionKpiReply aR = responseIterator.next();
for (int i = 0; i < aR.getPositionResultsCount(); i++) {
System.out.println(aR.getPositionResults(i));
}
total += aR.getPositionResultsCount();
}
responseIterator.shutdown();
assertEquals((long) (kpiRequests.size()), total);
} catch (DmeDnsException dde) {
Log.i(TAG, Log.getStackTraceString(dde));
assertFalse("queryQosKpiTest: DmeDnsException!", true);
} catch (ExecutionException ee) {
Log.i(TAG, Log.getStackTraceString(ee));
assertFalse("queryQosKpiTest: ExecutionException!", true);
} catch (StatusRuntimeException sre) {
Log.i(TAG, sre.getMessage());
Log.i(TAG, Log.getStackTraceString(sre));
assertFalse("queryQosKpiTest: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.i(TAG, Log.getStackTraceString(ie));
assertFalse("queryQosKpiTest: InterruptedException!", true);
} finally {
enableMockLocation(context, false);
if (responseIterator != null) {
responseIterator.shutdown();
}
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method testWiFiOnly.
// Mini test of wifi only:
@Test
public void testWiFiOnly() {
useWifiOnly = true;
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
assertEquals(true, me.isUseWifiOnly());
String overrideHost = "";
try {
overrideHost = me.generateDmeHostAddress();
} catch (DmeDnsException dde) {
assertTrue("Cannot set to use WiFi! DNS failure!", false);
}
assertEquals(me.wifiOnlyDmeHost, overrideHost);
me.setUseWifiOnly(useWifiOnly = false);
assertEquals(false, me.isUseWifiOnly());
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class EngineCallTest method verifyLocationTest.
@Test
public void verifyLocationTest() {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(context);
me.setUseWifiOnly(useWifiOnly);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
AppClient.VerifyLocationReply verifyLocationReply = null;
try {
enableMockLocation(context, true);
Location mockLoc = MockUtils.createLocation("verifyLocationTest", -96.994, 32.4824);
setMockLocation(context, mockLoc);
Location location = getTestLocation(-96.994, 32.4824);
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("VerifyLocation: DmeDnsException", true);
} catch (IOException ioe) {
Log.e(TAG, Log.getStackTraceString(ioe));
assertFalse("VerifyLocation: IOException!", true);
} catch (ExecutionException ee) {
Log.e(TAG, Log.getStackTraceString(ee));
assertFalse("VerifyLocation: ExecutionExecution!", true);
} catch (StatusRuntimeException sre) {
Log.e(TAG, Log.getStackTraceString(sre));
assertFalse("VerifyLocation: StatusRuntimeException!", true);
} catch (InterruptedException ie) {
Log.e(TAG, Log.getStackTraceString(ie));
assertFalse("VerifyLocation: InterruptedException!", true);
} finally {
enableMockLocation(context, false);
}
// Temporary.
assertEquals(0, verifyLocationReply.getVer());
assertEquals(AppClient.VerifyLocationReply.TowerStatus.TOWER_UNKNOWN, verifyLocationReply.getTowerStatus());
assertEquals(AppClient.VerifyLocationReply.GPSLocationStatus.LOC_ROAMING_COUNTRY_MATCH, verifyLocationReply.getGpsLocationStatus());
}
Aggregations