diff --git a/build.xml b/build.xml index 4e3025834..8fad1313f 100644 --- a/build.xml +++ b/build.xml @@ -253,7 +253,6 @@ ${build.major.number}.${build.minor.number}.${build.revision.number})]]> - diff --git a/lib/context-client-GNS.jar b/lib/context-client-GNS.jar deleted file mode 100644 index 28e3f8286..000000000 Binary files a/lib/context-client-GNS.jar and /dev/null differ diff --git a/lib/guava-22.0.jar b/lib/guava-22.0.jar new file mode 100644 index 000000000..fc7f3165c Binary files /dev/null and b/lib/guava-22.0.jar differ diff --git a/src/edu/umass/cs/contextservice/integration/ContextServiceGNSClient.java b/src/edu/umass/cs/contextservice/integration/ContextServiceGNSClient.java deleted file mode 100644 index 34ef4cbdc..000000000 --- a/src/edu/umass/cs/contextservice/integration/ContextServiceGNSClient.java +++ /dev/null @@ -1,99 +0,0 @@ -package edu.umass.cs.contextservice.integration; - - -import org.json.JSONObject; - -import edu.umass.cs.contextservice.client.ContextServiceClient; -import edu.umass.cs.contextservice.client.callback.implementations.NoopCallBack; -import edu.umass.cs.contextservice.client.callback.implementations.NoopUpdateReply; -import edu.umass.cs.contextservice.config.ContextServiceConfig.PrivacySchemes; -import edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commands.AbstractCommand; -import edu.umass.cs.gnsserver.main.GNSConfig; - -import java.util.logging.Level; -import edu.umass.cs.gnscommon.GNSProtocol; - -/** - * This class interacts with context service using context service client. - * It also implements the ContextServiceInterface. - * - * @author adipc - * - */ -public class ContextServiceGNSClient implements ContextServiceGNSInterface { - - private ContextServiceClient csClient; - private final NoopCallBack csNoopCallBack; - private final NoopUpdateReply csNoopUpdateReply; - - /** - * - * @param hostName - * @param portNum - */ - public ContextServiceGNSClient(String hostName, int portNum) - { - // catching everything here, otherwise exception doesn't get printed in executor service. - try - { - csClient = new ContextServiceClient (hostName, portNum, false, PrivacySchemes.NO_PRIVACY); - } catch (Error | Exception er) { - er.printStackTrace(); - } - - csNoopCallBack = new NoopCallBack(); - csNoopUpdateReply = new NoopUpdateReply(); - } - - - @Override - public void sendTiggerOnGnsCommand(JSONObject jsonFormattedCommand, AbstractCommand command, boolean blocking) { - try { - // code copied exactly from AbstractUpdate class - String guid = jsonFormattedCommand.getString(GNSProtocol.GUID.toString()); - String field = jsonFormattedCommand.optString(GNSProtocol.FIELD.toString(), null); - String value = jsonFormattedCommand.optString(GNSProtocol.VALUE.toString(), null); - //String oldValue = jsonFormattedCommand.optString(GNSProtocol.OLD_VALUE.toString(), null); - //int index = jsonFormattedCommand.optInt(GNSProtocol.N.toString(), -1); - JSONObject userJSON = jsonFormattedCommand.has(GNSProtocol.USER_JSON.toString()) ? new JSONObject(jsonFormattedCommand.getString(GNSProtocol.USER_JSON.toString())) : null; - // writer might be unspecified so we use the guid - String writer = jsonFormattedCommand.optString(GNSProtocol.WRITER.toString(), guid); - //String signature = jsonFormattedCommand.optString(GNSProtocol.SIGNATURE.toString(), null); - //String message = jsonFormattedCommand.optString(GNSProtocol.SIGNATUREFULLMESSAGE.toString(), null); - - if (writer.equals( - GNSProtocol.INTERNAL_QUERIER.toString() - //GNSConfig.getInternalOpSecret() - //Config.getGlobalString(GNSConfig.GNSC.INTERNAL_OP_SECRET) - )) { - writer = null; - } - - if (field == null) { - //responseCode = FieldAccess.updateUserJSON(guid, userJSON, writer, signature, message, handler); - - // full json update - // send the full JSON, contextServiceClient will check what attributes are supported - // by context service and send them to CS - GNSConfig.getLogger().log(Level.FINE, "Trigger to CS guid {0} userJSON {1}", - new Object[]{guid, userJSON}); - - csClient.sendUpdateWithCallBack(guid, null, userJSON, -1, - csNoopUpdateReply, csNoopCallBack); - } else { - // single field update - JSONObject attrValJSON = new JSONObject(); - attrValJSON.put(field, value); - - GNSConfig.getLogger().log(Level.FINE, "Trigger to CS guid {0} attrValJSON {1}", - new Object[]{guid, attrValJSON}); - - csClient.sendUpdateWithCallBack(guid, null, attrValJSON, -1, - csNoopUpdateReply, csNoopCallBack); - } - } catch (Exception | Error ex) { - ex.printStackTrace(); - } - } - -} diff --git a/src/edu/umass/cs/contextservice/integration/ContextServiceGNSInterface.java b/src/edu/umass/cs/contextservice/integration/ContextServiceGNSInterface.java deleted file mode 100644 index c9fe5673b..000000000 --- a/src/edu/umass/cs/contextservice/integration/ContextServiceGNSInterface.java +++ /dev/null @@ -1,35 +0,0 @@ -package edu.umass.cs.contextservice.integration; - -import org.json.JSONObject; - -import edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.commands.AbstractCommand; - -/** - * The ContextServiceGNSInterface. - */ -public interface ContextServiceGNSInterface { - - /** - * Sends update to context service. - * - * @param GUID is the updated GUID in String format - * @param attrValPairJSON JSONObject of attr:value pairs updated. attribute names - * are the keys of JSONObject. Multiple attributes can be updated once. - * @param versionNum version num of update, if there is none set to -1. - * @param blocking if set to true the call will block until the update completes in CS. - * for GNS preferably set to false. - */ - //public void sendUpdateToCS(String GUID, JSONObject attrValPairJSON, long versionNum, boolean blocking); - - /** - * Checks and sends trigger for the gns command. - * Blocking if set to true indicates blocking for the context service update to complete and recv - * the confirmation. - * Blocking should preferably set to false, as we don't want gns to block for CS udpates. - * - * @param jsonFormattedCommand gns formatted command - * @param command AbstractCommand - * @param blocking - */ - public void sendTiggerOnGnsCommand(JSONObject jsonFormattedCommand, AbstractCommand command, boolean blocking); -} diff --git a/src/edu/umass/cs/contextservice/integration/examples/ContextServiceExample.java b/src/edu/umass/cs/contextservice/integration/examples/ContextServiceExample.java deleted file mode 100644 index 978149334..000000000 --- a/src/edu/umass/cs/contextservice/integration/examples/ContextServiceExample.java +++ /dev/null @@ -1,179 +0,0 @@ -package edu.umass.cs.contextservice.integration.examples; - -import org.json.JSONArray; -import org.json.JSONObject; - -import edu.umass.cs.contextservice.client.ContextServiceClient; -import edu.umass.cs.contextservice.config.ContextServiceConfig.PrivacySchemes; -import edu.umass.cs.gnsclient.client.GNSClientCommands; -import edu.umass.cs.gnsclient.client.util.GuidEntry; -import edu.umass.cs.gnsclient.client.util.GuidUtils; - -/** - * @author westy - */ -public class ContextServiceExample { - // dallas region in texas area, for which we have weather alerts. - - /** - * - */ - public static final double LONGITUDE_MIN = -98.08; - - /** - * - */ - public static final double LONGITUDE_MAX = -96.01; - - /** - * - */ - public static final double LATITUDE_MAX = 33.635; - - /** - * - */ - public static final double LATITUDE_MIN = 31.854; - - /** - * - */ - public static final double LEFT = LONGITUDE_MIN; - - /** - * - */ - public static final double RIGHT = LONGITUDE_MAX; - - /** - * - */ - public static final double TOP = LATITUDE_MAX; - - /** - * - */ - public static final double BOTTOM = LATITUDE_MIN; - - /** - * - */ - public static final long QUERY_EXPIRY_TIME = 5 * 60 * 1000; // 5 min in ms - - /** - * - */ - public static final String ACCOUNT_ALIAS = "admincontextservice@gns.name"; - - /** - * - */ - public static GNSClientCommands client; - - /** - * - */ - public static ContextServiceClient csClient; - - /** - * - */ - public static GuidEntry account_guid; - - /** - * - * @param args - * @throws Exception - */ - public static void main(String[] args) throws Exception { - String csHost = args[0]; - int csPort = Integer.parseInt(args[1]); - - client = new GNSClientCommands(); - System.out.println("[Client connected to GNS]\n"); - - try { - /** - * Create an account GUID if one doesn't already exists. The true - * flag makes it verbosely print out what it is doing. The password - * is for future use and is needed mainly if the keypair is - * generated on the server in order to retrieve the private key. - * lookupOrCreateAccountGuid "cheats" by bypassing email-based or - * other verification mechanisms using a shared secret between the - * server and the client. - * - */ - System.out - .println("// account GUID creation\n" - + "GuidUtils.lookupOrCreateAccountGuid(client, ACCOUNT_ALIAS," - + " \"password\", true)\n"); - account_guid = GuidUtils.lookupOrCreateAccountGuid(client, - ACCOUNT_ALIAS, "password", true); - } catch (Exception | Error e) { - System.out.println("Exception during accountGuid creation: " + e); - e.printStackTrace(); - System.exit(1); - } - - System.out.println("csHost " + csHost + " csPort " + csPort); - - csClient = new ContextServiceClient (csHost, csPort, false, PrivacySchemes.NO_PRIVACY); - - String csSearchQuery = "latitude >= 32 AND latitude <= 33 AND " - + "longitude >= -98 AND longitude <= -97"; - - System.out.println("\n Issuing a search query to context service " - + csSearchQuery + "\n"); - - JSONArray resultArray = new JSONArray(); - - int replySize = csClient.sendSearchQuery(csSearchQuery, resultArray, QUERY_EXPIRY_TIME); - - System.out.println("Search query reply size " + replySize + " GUIDs " + resultArray + "\n"); - - JSONObject userJSON = new JSONObject(); - // user setting location inside the search query area. - userJSON.put("latitude", 32.5); - userJSON.put("longitude", -97.5); - - System.out.println("A user with GUID " + account_guid.getGuid() - + " entering the geofence specified in the search query by doing an update" - + ", latitude=32.5 and longitude=-97.5, in GNS\n"); - - client.update(account_guid, userJSON); - - // checking for trigger from context service that a new guid is added in an - // already existing group. This call blocks until there are non zero triggers. - JSONArray triggerArray = new JSONArray(); - csClient.getQueryUpdateTriggers(triggerArray); - - System.out.println("Context service sends a trigger showing that user with GUID " - + account_guid.getGuid() + " enters the geofence, the geofence's group GUID is in the TO_BE_ADDED field\n"); - for (int i = 0; i < triggerArray.length(); i++) { - System.out.println("Trigger JSON " + triggerArray.getJSONObject(i)); - } - - userJSON = new JSONObject(); - // user setting location inside the search query area. - userJSON.put("latitude", 31); - userJSON.put("longitude", -97.5); - - System.out.println("\n A user with guid" + account_guid.getGuid() - + " going out of the geofence specified in the search query by doing an update, latitude=31 and longitude=-97.5, in GNS\n"); - client.update(account_guid, userJSON); - - // checking for trigger from context service that the guid is removed from an - // already existing group. This call blocks until there are non zero triggers. - triggerArray = new JSONArray(); - csClient.getQueryUpdateTriggers(triggerArray); - - System.out.println("Context service sends a trigger showing that user with GUID " - + account_guid.getGuid() + " removed from the geofence, the geofence's group GUID is in TO_BE_REMOVED field "); - for (int i = 0; i < triggerArray.length(); i++) { - System.out.println("Trigger JSON " + triggerArray.getJSONObject(i)); - } - - System.out.println("\nBasic GNS CS test successful\n"); - System.exit(0); - } -} diff --git a/src/edu/umass/cs/gnsserver/gnsapp/GNSApp.java b/src/edu/umass/cs/gnsserver/gnsapp/GNSApp.java index e70033bb3..a4cc06342 100644 --- a/src/edu/umass/cs/gnsserver/gnsapp/GNSApp.java +++ b/src/edu/umass/cs/gnsserver/gnsapp/GNSApp.java @@ -15,8 +15,6 @@ * Initial developer(s): Westy, arun */ package edu.umass.cs.gnsserver.gnsapp; -import edu.umass.cs.contextservice.integration.ContextServiceGNSClient; -import edu.umass.cs.contextservice.integration.ContextServiceGNSInterface; import edu.umass.cs.gigapaxos.interfaces.AppRequestParserBytes; import edu.umass.cs.gigapaxos.interfaces.ClientMessenger; import edu.umass.cs.gigapaxos.interfaces.ClientRequest; @@ -138,11 +136,6 @@ private static boolean enqueueCommand() { */ private ActiveCodeHandler activeCodeHandler; - /** - * context service interface - */ - private ContextServiceGNSInterface contextServiceGNSClient; - /** * The non-secure http server */ @@ -471,22 +464,7 @@ private void GnsAppConstructor(JSONMessenger messenger) throws IOExcepti } this.activeCodeHandler = !Config.getGlobalBoolean(GNSConfig.GNSC.DISABLE_ACTIVE_CODE) ? new ActiveCodeHandler(nodeID) : null; - - // context service init - if (Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS)) { - String nodeAddressString = Config.getGlobalString(GNSConfig.GNSC.CNS_NODE_ADDRESS); - - String[] parsed = nodeAddressString.split(":"); - - assert (parsed.length == 2); - - String host = parsed[0]; - int port = Integer.parseInt(parsed[1]); - GNSConfig.getLogger().fine("ContextServiceGNSClient initialization started"); - contextServiceGNSClient = new ContextServiceGNSClient(host, port); - GNSConfig.getLogger().fine("ContextServiceGNSClient initialization completed"); - } - + constructed = true; } @@ -824,13 +802,6 @@ public ClientRequestHandlerInterface getRequestHandler() { return requestHandler; } - /** - * @return ContextServiceGNSInterface - */ - public ContextServiceGNSInterface getContextServiceGNSClient() { - return contextServiceGNSClient; - } - private void startDNS() throws SecurityException, SocketException, UnknownHostException { try { diff --git a/src/edu/umass/cs/gnsserver/gnsapp/GNSApplicationInterface.java b/src/edu/umass/cs/gnsserver/gnsapp/GNSApplicationInterface.java index 940a5306b..f2145122c 100644 --- a/src/edu/umass/cs/gnsserver/gnsapp/GNSApplicationInterface.java +++ b/src/edu/umass/cs/gnsserver/gnsapp/GNSApplicationInterface.java @@ -19,13 +19,11 @@ */ package edu.umass.cs.gnsserver.gnsapp; -import edu.umass.cs.contextservice.integration.ContextServiceGNSInterface; import edu.umass.cs.gigapaxos.interfaces.Request; import edu.umass.cs.gnscommon.packets.CommandPacket; import edu.umass.cs.gnsserver.activecode.ActiveCodeHandler; import edu.umass.cs.gnsserver.gnsapp.clientCommandProcessor.ClientRequestHandlerInterface; import edu.umass.cs.gnsserver.gnsapp.recordmap.BasicRecordMap; -import edu.umass.cs.reconfiguration.interfaces.ReconfigurableNodeConfig; import java.io.IOException; @@ -88,11 +86,6 @@ public interface GNSApplicationInterface { public void sendToClient(CommandPacket originalRequest, Request response, JSONObject responseJSON) throws IOException; - /** - * @return ContextServiceGNSInterface - */ - public ContextServiceGNSInterface getContextServiceGNSClient(); - /** * Returns the request handler. * @@ -106,5 +99,4 @@ public void sendToClient(CommandPacket originalRequest, Request response, JSONOb * @return the active code handler */ ActiveCodeHandler getActiveCodeHandler(); - -} +} \ No newline at end of file diff --git a/src/edu/umass/cs/gnsserver/gnsapp/clientCommandProcessor/commandSupport/CommandHandler.java b/src/edu/umass/cs/gnsserver/gnsapp/clientCommandProcessor/commandSupport/CommandHandler.java index e063bff32..f65ad6a8e 100644 --- a/src/edu/umass/cs/gnsserver/gnsapp/clientCommandProcessor/commandSupport/CommandHandler.java +++ b/src/edu/umass/cs/gnsserver/gnsapp/clientCommandProcessor/commandSupport/CommandHandler.java @@ -138,27 +138,6 @@ private static void runCommand(CommandPacket commandPacket, new Object[]{handler.getApp(), e}); e.printStackTrace(); } - - // reply to client is true, this means this is the active replica - // that recvd the request from the gnsClient. So, let's check for - // sending trigger to Context service here. - if (Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS)) { - if (!doNotReplyToClient) { - - if (command.getClass().getSuperclass() == AbstractUpdate.class) { - GNSConfig - .getLogger() - .log(Level.FINE, - "{0} sending trigger to context service for {1}:{2}", - new Object[]{handler.getApp(), command, - jsonFormattedCommand}); - - app.getContextServiceGNSClient().sendTiggerOnGnsCommand( - jsonFormattedCommand, command, false); - } - } - } - } private static CommandPacket addMessageWithoutSignatureToCommand( diff --git a/src/edu/umass/cs/gnsserver/main/GNSConfig.java b/src/edu/umass/cs/gnsserver/main/GNSConfig.java index 7efc2a126..bde22b121 100644 --- a/src/edu/umass/cs/gnsserver/main/GNSConfig.java +++ b/src/edu/umass/cs/gnsserver/main/GNSConfig.java @@ -219,18 +219,6 @@ public static enum GNSC implements Config.ConfigurableEnum, * requests to DNS and GNS servers. */ DNS_ONLY(false), - // - // Contect Name Service - // - /** - * If set to true enables update forwarding to CNS - */ - ENABLE_CNS(false), - /** - * Ip address:port of one node of CNS. If ENABLE_CNS is set to true then - * this option should definitely be set. - */ - CNS_NODE_ADDRESS(NONE), /** * The alias of the private key in the java keyStore. */ diff --git a/test/edu/umass/cs/gnsclient/client/integrationtests/ServerIntegrationTest.java b/test/edu/umass/cs/gnsclient/client/integrationtests/ServerIntegrationTest.java index 0901cb1b3..60f140dfc 100644 --- a/test/edu/umass/cs/gnsclient/client/integrationtests/ServerIntegrationTest.java +++ b/test/edu/umass/cs/gnsclient/client/integrationtests/ServerIntegrationTest.java @@ -34,8 +34,7 @@ import org.junit.runner.Result; import org.junit.runner.notification.Failure; -import edu.umass.cs.contextservice.client.ContextServiceClient; -import edu.umass.cs.contextservice.config.ContextServiceConfig.PrivacySchemes; + import edu.umass.cs.gigapaxos.PaxosConfig; import edu.umass.cs.gigapaxos.paxosutil.RequestInstrumenter; import edu.umass.cs.gnsclient.client.GNSClient; @@ -58,12 +57,10 @@ import edu.umass.cs.gnscommon.utils.RandomString; import edu.umass.cs.gnscommon.utils.ThreadUtils; import edu.umass.cs.gnsserver.database.MongoRecords; -import edu.umass.cs.gnsserver.main.GNSConfig; import edu.umass.cs.gnsserver.utils.DefaultGNSTest; import edu.umass.cs.reconfiguration.ReconfigurableNode; import edu.umass.cs.reconfiguration.ReconfigurationConfig; import edu.umass.cs.reconfiguration.reconfigurationutils.DefaultNodeConfig; -import edu.umass.cs.utils.Config; import edu.umass.cs.utils.Repeat; import edu.umass.cs.utils.Util; @@ -3567,51 +3564,7 @@ public void test_561_QueryLookupSecondGroup(String groupTestFieldName, GuidEntry failWithStackTrace("Exception executing selectLookupGroupQuery: ", e); } } - - /** - * Test to check context service triggers. - */ - // these two attributes right now are supported by CS - @Test - @Repeat(times = REPEAT) - public void test_620_contextServiceTest() { - // run it only when CS is enabled - // to check if context service is enabled. - boolean enableContextService = Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS); - String csIPPort = Config.getGlobalString(GNSConfig.GNSC.CNS_NODE_ADDRESS); - if (enableContextService) { - try { - JSONObject attrValJSON = new JSONObject(); - attrValJSON.put("geoLocationCurrentLat", 42.466); - attrValJSON.put("geoLocationCurrentLong", -72.58); - - clientCommands.update(masterGuid, attrValJSON); - // just wait for 2 sec before sending search - Thread.sleep(1000); - - String[] parsed = csIPPort.split(":"); - String csIP = parsed[0]; - int csPort = Integer.parseInt(parsed[1]); - - ContextServiceClient csClient = new ContextServiceClient(csIP, csPort, false, PrivacySchemes.NO_PRIVACY); - - // context service query format - String query = "geoLocationCurrentLat >= 40 " - + "AND geoLocationCurrentLat <= 50 AND " - + "geoLocationCurrentLong >= -80 AND " - + "geoLocationCurrentLong <= -70"; - JSONArray resultArray = new JSONArray(); - // third argument is arbitrary expiry time, not used now - int resultSize = csClient.sendSearchQuery(query, resultArray, - 300000); - Assert.assertThat(resultSize, Matchers.greaterThanOrEqualTo(1)); - - } catch (Exception e) { - failWithStackTrace("Exception during contextServiceTest: ", e); - } - } - } - + /** * A basic test to insure that setting LNS Proxy minimally doesn't break. */ diff --git a/test/edu/umass/cs/gnsclient/client/singletests/ContextServiceTest.java b/test/edu/umass/cs/gnsclient/client/singletests/ContextServiceTest.java deleted file mode 100644 index 57d6cd93b..000000000 --- a/test/edu/umass/cs/gnsclient/client/singletests/ContextServiceTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * - * Copyright (c) 2015 University of Massachusetts - * - * Licensed under the Apache License, Version 2.0 (the "License"); you - * may not use this file except in compliance with the License. You - * may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - * implied. See the License for the specific language governing - * permissions and limitations under the License. - * - * Initial developer(s): Westy - * - */ -package edu.umass.cs.gnsclient.client.singletests; - -import edu.umass.cs.contextservice.client.ContextServiceClient; -import edu.umass.cs.contextservice.config.ContextServiceConfig.PrivacySchemes; -import edu.umass.cs.gnsclient.client.GNSClientCommands; -import edu.umass.cs.gnsclient.client.util.GuidEntry; -import edu.umass.cs.gnsclient.client.util.GuidUtils; - -import edu.umass.cs.gnscommon.GNSProtocol; -import edu.umass.cs.gnscommon.exceptions.client.ClientException; -import edu.umass.cs.gnscommon.utils.RandomString; -import edu.umass.cs.gnsserver.main.GNSConfig; -import edu.umass.cs.gnsserver.utils.DefaultGNSTest; -import edu.umass.cs.utils.Config; -import edu.umass.cs.utils.Repeat; -import edu.umass.cs.utils.Utils; -import java.io.IOException; - -import org.hamcrest.Matchers; -import org.json.JSONArray; -import org.json.JSONObject; - -import org.junit.Assert; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - -/** - * Basic test for the GNS using the UniversalTcpClient. - * - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ContextServiceTest extends DefaultGNSTest { - - private static final int REPEAT = 10; - - private static GNSClientCommands clientCommands; - private static GuidEntry masterGuid; - - /** - * - */ - public ContextServiceTest() { - if (clientCommands == null) { - try { - clientCommands = new GNSClientCommands(); - clientCommands.setForceCoordinatedReads(true); - } catch (IOException e) { - Utils.failWithStackTrace("Exception creating client: " + e); - } - } - try { - masterGuid = GuidUtils.getGUIDKeys(globalAccountName); - } catch (Exception e) { - Utils.failWithStackTrace("Exception when we were not expecting it: " + e); - } - } - - /** - * Test to check context service triggers. - */ - // these two attributes right now are supported by CS - @Test - @Repeat(times = REPEAT) - public void test_620_contextServiceTest() { - // run it only when CS is enabled - // to check if context service is enabled. - boolean enableContextService = Config.getGlobalBoolean(GNSConfig.GNSC.ENABLE_CNS); - String csIPPort = Config.getGlobalString(GNSConfig.GNSC.CNS_NODE_ADDRESS); - if (enableContextService) { - try { - JSONObject attrValJSON = new JSONObject(); - attrValJSON.put("geoLocationCurrentLat", 42.466); - attrValJSON.put("geoLocationCurrentLong", -72.58); - - clientCommands.update(masterGuid, attrValJSON); - // just wait for 2 sec before sending search - Thread.sleep(1000); - - String[] parsed = csIPPort.split(":"); - String csIP = parsed[0]; - int csPort = Integer.parseInt(parsed[1]); - - ContextServiceClient csClient = new ContextServiceClient(csIP, csPort, false, PrivacySchemes.NO_PRIVACY); - - // context service query format - String query = "geoLocationCurrentLat >= 40 " - + "AND geoLocationCurrentLat <= 50 AND " - + "geoLocationCurrentLong >= -80 AND " - + "geoLocationCurrentLong <= -70"; - JSONArray resultArray = new JSONArray(); - // third argument is arbitrary expiry time, not used now - int resultSize = csClient.sendSearchQuery(query, resultArray, - 300000); - Assert.assertThat(resultSize, Matchers.greaterThanOrEqualTo(1)); - - } catch (Exception e) { - Utils.failWithStackTrace("Exception during contextServiceTest: ", e); - } - } - } - -}