pirk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From raydul...@apache.org
Subject incubator-pirk git commit: PIRK-79 Allow json serialization to deserialize a queryInfo object that has only the name of a query schema. - closes apache/incubator-pirk#115
Date Tue, 01 Nov 2016 16:02:20 GMT
Repository: incubator-pirk
Updated Branches:
  refs/heads/master c3508af5a -> 2c9288523


PIRK-79 Allow json serialization to deserialize a queryInfo object that has only the name
of a query schema. - closes apache/incubator-pirk#115


Project: http://git-wip-us.apache.org/repos/asf/incubator-pirk/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-pirk/commit/2c928852
Tree: http://git-wip-us.apache.org/repos/asf/incubator-pirk/tree/2c928852
Diff: http://git-wip-us.apache.org/repos/asf/incubator-pirk/diff/2c928852

Branch: refs/heads/master
Commit: 2c9288523882ecac35dd6c3b6cb9d238c2a0d2b4
Parents: c3508af
Author: raydulany <raydulany@apache.org>
Authored: Tue Nov 1 11:59:56 2016 -0400
Committer: Walter Ray-Dulany <raydulany@gmail.com>
Committed: Tue Nov 1 12:01:18 2016 -0400

----------------------------------------------------------------------
 pom.xml                                         |   7 +
 .../org/apache/pirk/encryption/Paillier.java    |  33 ++++
 .../apache/pirk/querier/wideskies/Querier.java  |  25 +++
 .../org/apache/pirk/query/wideskies/Query.java  |  30 ++++
 .../pirk/query/wideskies/QueryDeserializer.java | 165 -------------------
 .../apache/pirk/query/wideskies/QueryInfo.java  |  42 +++++
 .../pirk/response/wideskies/Response.java       |  21 +++
 .../wideskies/ResponseDeserializer.java         |  60 -------
 .../apache/pirk/schema/query/QuerySchema.java   |  33 ++++
 .../pirk/serialization/JsonSerializer.java      |   8 +-
 .../distributed/testsuite/DistTestSuite.java    |   2 +-
 .../org/apache/pirk/test/utils/BaseTests.java   |   4 +-
 .../apache/pirk/test/utils/StandaloneQuery.java |  35 ++--
 .../pirk/serialization/SerializationTest.java   | 136 ++++++++++++++-
 .../wideskies/standalone/StandaloneTest.java    |   5 +-
 15 files changed, 346 insertions(+), 260 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 88dff10..e0aa532 100644
--- a/pom.xml
+++ b/pom.xml
@@ -108,6 +108,13 @@
             <version>3.6.1</version>
         </dependency>
 
+        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.7</version>
+        </dependency>
+
         <dependency>
             <groupId>com.googlecode.json-simple</groupId>
             <artifactId>json-simple</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/encryption/Paillier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/encryption/Paillier.java b/src/main/java/org/apache/pirk/encryption/Paillier.java
index 5bc4694..720c10f 100644
--- a/src/main/java/org/apache/pirk/encryption/Paillier.java
+++ b/src/main/java/org/apache/pirk/encryption/Paillier.java
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.Serializable;
 import java.math.BigInteger;
+import java.util.Objects;
 
 /**
  * Implementation of the Paillier cryptosystem.
@@ -72,9 +73,11 @@ public final class Paillier implements Serializable
 
   private static final Logger logger = LoggerFactory.getLogger(Paillier.class);
 
+  @Expose
   private BigInteger p; // large prime
   @Expose
   private BigInteger q; // large prime
+  
   private BigInteger N; // N=pq, RSA modulus
 
   private BigInteger NSquared; // NSquared = N^2
@@ -340,4 +343,34 @@ public final class Paillier implements Serializable
     return "p = " + p.intValue() + " q = " + q.intValue() + " N = " + N.intValue() + " NSquared
= " + NSquared.intValue() + " lambdaN = " + lambdaN.intValue()
         + " bitLength = " + bitLength;
   }
+
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    Paillier paillier = (Paillier) o;
+
+    if (bitLength != paillier.bitLength)
+      return false;
+    if (!p.equals(paillier.p))
+      return false;
+    if (!q.equals(paillier.q))
+      return false;
+    if (!N.equals(paillier.N))
+      return false;
+    if (!NSquared.equals(paillier.NSquared))
+      return false;
+    if (!lambdaN.equals(paillier.lambdaN))
+      return false;
+    return w.equals(paillier.w);
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(p, q, N, NSquared, lambdaN, w, bitLength);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/querier/wideskies/Querier.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/querier/wideskies/Querier.java b/src/main/java/org/apache/pirk/querier/wideskies/Querier.java
index bb08cbb..7a69580 100644
--- a/src/main/java/org/apache/pirk/querier/wideskies/Querier.java
+++ b/src/main/java/org/apache/pirk/querier/wideskies/Querier.java
@@ -21,6 +21,7 @@ package org.apache.pirk.querier.wideskies;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 
 import com.google.gson.annotations.Expose;
 import org.apache.pirk.encryption.Paillier;
@@ -54,6 +55,30 @@ public class Querier implements Serializable, Storable
   @Expose
   private Map<Integer,String> embedSelectorMap = null;
 
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    Querier querier = (Querier) o;
+
+    if (!query.equals(querier.query))
+      return false;
+    if (!paillier.equals(querier.paillier))
+      return false;
+    if (!selectors.equals(querier.selectors))
+      return false;
+    return embedSelectorMap != null ? embedSelectorMap.equals(querier.embedSelectorMap) :
querier.embedSelectorMap == null;
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(query, paillier, selectors, embedSelectorMap);
+  }
+
   public Querier(List<String> selectorsInput, Paillier paillierInput, Query queryInput,
Map<Integer,String> embedSelectorMapInput)
   {
     selectors = selectorsInput;

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/query/wideskies/Query.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/query/wideskies/Query.java b/src/main/java/org/apache/pirk/query/wideskies/Query.java
index cf5a3a9..dd18297 100644
--- a/src/main/java/org/apache/pirk/query/wideskies/Query.java
+++ b/src/main/java/org/apache/pirk/query/wideskies/Query.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import java.math.BigInteger;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.SortedMap;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Consumer;
@@ -56,6 +57,7 @@ public class Query implements Serializable, Storable
 
   // lookup table for exponentiation of query vectors - based on dataPartitionBitSize
   // element -> <power, element^power mod N^2>
+  @Expose
   private Map<BigInteger,Map<Integer,BigInteger>> expTable = new ConcurrentHashMap<>();
 
   // File based lookup table for modular exponentiation
@@ -152,4 +154,32 @@ public class Query implements Serializable, Storable
     Map<Integer,BigInteger> powerMap = expTable.get(value);
     return (powerMap == null) ? null : powerMap.get(power);
   }
+
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    Query query = (Query) o;
+
+    if (!queryInfo.equals(query.queryInfo))
+      return false;
+    if (!queryElements.equals(query.queryElements))
+      return false;
+    if (expTable != null ? !expTable.equals(query.expTable) : query.expTable != null)
+      return false;
+    if (expFileBasedLookup != null ? !expFileBasedLookup.equals(query.expFileBasedLookup)
: query.expFileBasedLookup != null)
+      return false;
+    if (!N.equals(query.N))
+      return false;
+    return NSquared.equals(query.NSquared);
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(queryInfo, queryElements, expTable, expFileBasedLookup, N, NSquared);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/query/wideskies/QueryDeserializer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/query/wideskies/QueryDeserializer.java b/src/main/java/org/apache/pirk/query/wideskies/QueryDeserializer.java
deleted file mode 100644
index 3a5256d..0000000
--- a/src/main/java/org/apache/pirk/query/wideskies/QueryDeserializer.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-package org.apache.pirk.query.wideskies;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.reflect.TypeToken;
-import org.apache.pirk.schema.query.QuerySchema;
-import org.apache.pirk.schema.query.filter.DataFilter;
-import org.apache.pirk.schema.query.filter.FilterFactory;
-import org.apache.pirk.utils.PIRException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.lang.reflect.Type;
-import java.math.BigInteger;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.UUID;
-
-/**
- * Custom deserializer for Query class for Gson.
- */
-public class QueryDeserializer implements JsonDeserializer<Query>
-{
-
-  private static final Logger logger = LoggerFactory.getLogger(QueryDeserializer.class);
-
-  private static final Gson gson = new Gson();
-
-  @Override
-  public Query deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext
jsonDeserializationContext) throws JsonParseException
-  {
-    JsonObject jsonObject = jsonElement.getAsJsonObject();
-    logger.info("Got query json:" + jsonObject.toString());
-    // Check the version number.
-    long queryVersion = jsonObject.get("queryVersion").getAsLong();
-    if (queryVersion != Query.querySerialVersionUID)
-    {
-      throw new JsonParseException(
-          "Attempt to deserialize unsupported query version. Supported: " + Query.querySerialVersionUID
+ "; Received: " + queryVersion);
-    }
-    // Then deserialize the Query Info
-    QueryInfo queryInfo = deserializeInfo(jsonObject.get("queryInfo").getAsJsonObject());
-    SortedMap<Integer,BigInteger> queryElements = gson.fromJson(jsonObject.get("queryElements"),
new TypeToken<SortedMap<Integer,BigInteger>>()
-    {}.getType());
-    BigInteger N = new BigInteger(jsonObject.get("n").getAsString());
-    BigInteger NSquared = new BigInteger(jsonObject.get("nsquared").getAsString());
-    Map<Integer,String> expFileBasedLookup = gson.fromJson(jsonObject.get("expFileBasedLookup"),
new TypeToken<Map<Integer,String>>()
-    {}.getType());
-
-    Query query = new Query(queryInfo, N, NSquared, queryElements);
-    query.setExpFileBasedLookup(expFileBasedLookup);
-    return query;
-  }
-
-  /**
-   * Deserializes a QueryInfo JsonObject
-   *
-   * @param queryInfoJson
-   *          A JsonObject at the root of a serialized QueryInfo object.
-   * @return A QueryInfo object of the deserialized Json.
-   * @throws JsonParseException
-   */
-  public static QueryInfo deserializeInfo(JsonObject queryInfoJson) throws JsonParseException
-  {
-    // First check the version.
-    long infoVersion = queryInfoJson.get("queryInfoVersion").getAsLong();
-    if (infoVersion != QueryInfo.queryInfoSerialVersionUID)
-    {
-      throw new JsonParseException(
-          "Attempt to deserialize unsupported query info version. Supported: " + QueryInfo.queryInfoSerialVersionUID
+ "; Received: " + infoVersion);
-    }
-    // Deserialize the QuerySchema next, accounting for the possibility that it is null.
-    QuerySchema querySchema;
-    if (queryInfoJson.get("qSchema").isJsonNull())
-    {
-      querySchema = null;
-    }
-    else
-    {
-      querySchema = deserializeSchema(queryInfoJson.get("qSchema").getAsJsonObject());
-    }
-    // Now start making the QueryInfo object.
-    QueryInfo info = new QueryInfo(UUID.fromString(queryInfoJson.get("identifier").getAsString()),
queryInfoJson.get("numSelectors").getAsInt(),
-        queryInfoJson.get("hashBitSize").getAsInt(), queryInfoJson.get("hashKey").getAsString(),
queryInfoJson.get("dataPartitionBitSize").getAsInt(),
-        queryInfoJson.get("queryType").getAsString(), queryInfoJson.get("useExpLookupTable").getAsBoolean(),
queryInfoJson.get("embedSelector").getAsBoolean(),
-        queryInfoJson.get("useHDFSExpLookupTable").getAsBoolean(), queryInfoJson.get("numBitsPerDataElement").getAsInt(),
querySchema);
-    return info;
-  }
-
-  /**
-   * Deserializes a QuerySchema JsonObject
-   *
-   * @param querySchemaJson
-   *          A JsonObject at the root of a serialized QuerySchema object.
-   * @return A QuerySchema object of the deserialized Json.
-   * @throws JsonParseException
-   */
-  private static QuerySchema deserializeSchema(JsonObject querySchemaJson) throws JsonParseException
-  {
-    // Deserialize The Query Schema First.
-    long schemaVersion = querySchemaJson.get("querySchemaVersion").getAsLong();
-    if (schemaVersion != QuerySchema.querySchemaSerialVersionUID)
-    {
-      throw new JsonParseException(
-          "Attempt to deserialize unsupported query info version. Supported: " + QueryInfo.queryInfoSerialVersionUID
+ "; Received: " + schemaVersion);
-    }
-    String dataFilterName = querySchemaJson.get("filterTypeName").getAsString();
-    Set<String> filteredElementNames;
-    try
-    {
-      filteredElementNames = gson.fromJson(querySchemaJson.get("filteredElementNames"), new
TypeToken<Set<String>>()
-      {}.getType());
-    } catch (Exception e)
-    {
-      logger.warn("No filtered element names for Query Schema deserialization.");
-      filteredElementNames = null;
-    }
-    // Set up the data filter
-    DataFilter dataFilter;
-    try
-    {
-      dataFilter = FilterFactory.getFilter(dataFilterName, filteredElementNames);
-    } catch (IOException | PIRException e)
-    {
-      logger.error("Error trying to create data filter from JSON.", e);
-      throw new JsonParseException(e);
-    }
-
-    QuerySchema querySchema = new QuerySchema(querySchemaJson.get("schemaName").getAsString(),
querySchemaJson.get("dataSchemaName").getAsString(),
-        querySchemaJson.get("selectorName").getAsString(), dataFilterName, dataFilter, querySchemaJson.get("dataElementSize").getAsInt());
-    List<String> elementNames = gson.fromJson(querySchemaJson.get("elementNames"),
new TypeToken<List<String>>()
-    {}.getType());
-    querySchema.getElementNames().addAll(elementNames);
-    HashMap<String,String> additionalFields = gson.fromJson(querySchemaJson.get("additionalFields"),
new TypeToken<HashMap<String,String>>()
-    {}.getType());
-    querySchema.getAdditionalFields().putAll(additionalFields);
-    return querySchema;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java b/src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java
index a08819b..74b6b65 100644
--- a/src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java
+++ b/src/main/java/org/apache/pirk/query/wideskies/QueryInfo.java
@@ -28,6 +28,7 @@ import org.slf4j.LoggerFactory;
 import java.io.Serializable;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.UUID;
 
 /**
@@ -286,4 +287,45 @@ public class QueryInfo implements Serializable, Cloneable
       throw new RuntimeException(e);
     }
   }
+
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    QueryInfo queryInfo = (QueryInfo) o;
+
+    if (numSelectors != queryInfo.numSelectors)
+      return false;
+    if (hashBitSize != queryInfo.hashBitSize)
+      return false;
+    if (numBitsPerDataElement != queryInfo.numBitsPerDataElement)
+      return false;
+    if (dataPartitionBitSize != queryInfo.dataPartitionBitSize)
+      return false;
+    if (numPartitionsPerDataElement != queryInfo.numPartitionsPerDataElement)
+      return false;
+    if (useExpLookupTable != queryInfo.useExpLookupTable)
+      return false;
+    if (useHDFSExpLookupTable != queryInfo.useHDFSExpLookupTable)
+      return false;
+    if (embedSelector != queryInfo.embedSelector)
+      return false;
+    if (!identifier.equals(queryInfo.identifier))
+      return false;
+    if (!queryType.equals(queryInfo.queryType))
+      return false;
+    if (!hashKey.equals(queryInfo.hashKey))
+      return false;
+    return qSchema != null ? qSchema.equals(queryInfo.qSchema) : queryInfo.qSchema == null;
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(identifier, numSelectors, queryType, hashBitSize, hashKey, numBitsPerDataElement,
useExpLookupTable, useHDFSExpLookupTable,
+        embedSelector, qSchema);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/response/wideskies/Response.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/response/wideskies/Response.java b/src/main/java/org/apache/pirk/response/wideskies/Response.java
index 5fa0abd..7c22d35 100644
--- a/src/main/java/org/apache/pirk/response/wideskies/Response.java
+++ b/src/main/java/org/apache/pirk/response/wideskies/Response.java
@@ -20,6 +20,7 @@ package org.apache.pirk.response.wideskies;
 
 import java.io.Serializable;
 import java.math.BigInteger;
+import java.util.Objects;
 import java.util.TreeMap;
 
 import com.google.gson.annotations.Expose;
@@ -71,4 +72,24 @@ public class Response implements Serializable, Storable
   {
     responseElements.put(position, element);
   }
+
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    Response response = (Response) o;
+
+    if (!queryInfo.equals(response.queryInfo))
+      return false;
+    return responseElements.equals(response.responseElements);
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(queryInfo, responseElements);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/response/wideskies/ResponseDeserializer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/response/wideskies/ResponseDeserializer.java b/src/main/java/org/apache/pirk/response/wideskies/ResponseDeserializer.java
deleted file mode 100644
index 719833f..0000000
--- a/src/main/java/org/apache/pirk/response/wideskies/ResponseDeserializer.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
- */
-package org.apache.pirk.response.wideskies;
-
-import com.google.gson.Gson;
-import com.google.gson.JsonDeserializationContext;
-import com.google.gson.JsonDeserializer;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParseException;
-import com.google.gson.reflect.TypeToken;
-import org.apache.pirk.query.wideskies.QueryDeserializer;
-import org.apache.pirk.query.wideskies.QueryInfo;
-
-import java.lang.reflect.Type;
-import java.math.BigInteger;
-import java.util.TreeMap;
-
-/**
- * Custom deserializer for Response class for Gson.
- */
-public class ResponseDeserializer implements JsonDeserializer<Response>
-{
-
-  private static final Gson gson = new Gson();
-
-  @Override
-  public Response deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext
jsonDeserializationContext) throws JsonParseException
-  {
-    final JsonObject jsonObject = jsonElement.getAsJsonObject();
-    long responseVersion = jsonObject.get("responseVersion").getAsLong();
-    if (responseVersion != Response.responseSerialVersionUID)
-    {
-      throw new JsonParseException("\"Attempt to deserialize unsupported query version. Supported:
\"\n"
-          + "          + Response.responseSerialVersionUID + \"; Received: \" + responseVersion");
-    }
-    QueryInfo queryInfo = QueryDeserializer.deserializeInfo(jsonObject.get("queryInfo").getAsJsonObject());
-    Response response = new Response(queryInfo);
-    TreeMap<Integer,BigInteger> responseElements = gson.fromJson(jsonObject.get("responseElements"),
new TypeToken<TreeMap<Integer,BigInteger>>()
-    {}.getType());
-    response.setResponseElements(responseElements);
-    return response;
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/schema/query/QuerySchema.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/schema/query/QuerySchema.java b/src/main/java/org/apache/pirk/schema/query/QuerySchema.java
index 59d74fe..dc2588f 100644
--- a/src/main/java/org/apache/pirk/schema/query/QuerySchema.java
+++ b/src/main/java/org/apache/pirk/schema/query/QuerySchema.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Objects;
 import java.util.Set;
 
 /**
@@ -194,4 +195,36 @@ public class QuerySchema implements Serializable
   {
     return additionalFields.get(key);
   }
+
+  @Override public boolean equals(Object o)
+  {
+    if (this == o)
+      return true;
+    if (o == null || getClass() != o.getClass())
+      return false;
+
+    QuerySchema that = (QuerySchema) o;
+
+    if (dataElementSize != that.dataElementSize)
+      return false;
+    if (!schemaName.equals(that.schemaName))
+      return false;
+    if (!dataSchemaName.equals(that.dataSchemaName))
+      return false;
+    if (!selectorName.equals(that.selectorName))
+      return false;
+    if (!elementNames.equals(that.elementNames))
+      return false;
+    if (filterTypeName != null ? !filterTypeName.equals(that.filterTypeName) : that.filterTypeName
!= null)
+      return false;
+    if (!filteredElementNames.equals(that.filteredElementNames))
+      return false;
+    return additionalFields.equals(that.additionalFields);
+
+  }
+
+  @Override public int hashCode()
+  {
+    return Objects.hash(schemaName, dataSchemaName, selectorName, elementNames, filterTypeName,
filteredElementNames, dataElementSize, additionalFields);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/serialization/JsonSerializer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/serialization/JsonSerializer.java b/src/main/java/org/apache/pirk/serialization/JsonSerializer.java
index d3246ce..18ece86 100644
--- a/src/main/java/org/apache/pirk/serialization/JsonSerializer.java
+++ b/src/main/java/org/apache/pirk/serialization/JsonSerializer.java
@@ -22,11 +22,7 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import org.apache.pirk.querier.wideskies.Querier;
 import org.apache.pirk.querier.wideskies.QuerierDeserializer;
-import org.apache.pirk.query.wideskies.QueryDeserializer;
-import org.apache.pirk.response.wideskies.Response;
-import org.apache.pirk.response.wideskies.ResponseDeserializer;
 
-import javax.management.Query;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -37,8 +33,8 @@ import java.io.Writer;
 
 public class JsonSerializer extends SerializationService
 {
-  public static final Gson gson = new GsonBuilder().registerTypeAdapter(Response.class, new
ResponseDeserializer())
-      .registerTypeAdapter(Query.class, new QueryDeserializer()).registerTypeAdapter(Querier.class,
new QuerierDeserializer()).setPrettyPrinting()
+  public static final Gson gson = new GsonBuilder()
+      .registerTypeAdapter(Querier.class, new QuerierDeserializer()).setPrettyPrinting()
       .excludeFieldsWithoutExposeAnnotation().serializeNulls().create();
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/test/distributed/testsuite/DistTestSuite.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/test/distributed/testsuite/DistTestSuite.java b/src/main/java/org/apache/pirk/test/distributed/testsuite/DistTestSuite.java
index 4cf5211..4285bfd 100644
--- a/src/main/java/org/apache/pirk/test/distributed/testsuite/DistTestSuite.java
+++ b/src/main/java/org/apache/pirk/test/distributed/testsuite/DistTestSuite.java
@@ -402,7 +402,7 @@ public class DistTestSuite
   // Base method to perform query
   // TODO: This could be changed to pass in the platform instead of isSpark and isStreaming...
   @SuppressWarnings("unused")
-  public static List<QueryResponseJSON> performQuery(String queryType, ArrayList<String>
selectors, FileSystem fs, boolean isSpark, int numThreads,
+  public static List<QueryResponseJSON> performQuery(String queryType, List<String>
selectors, FileSystem fs, boolean isSpark, int numThreads,
       boolean isStreaming) throws Exception
   {
     logger.info("performQuery: ");

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/test/utils/BaseTests.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/test/utils/BaseTests.java b/src/main/java/org/apache/pirk/test/utils/BaseTests.java
index fc85df0..3385fa5 100644
--- a/src/main/java/org/apache/pirk/test/utils/BaseTests.java
+++ b/src/main/java/org/apache/pirk/test/utils/BaseTests.java
@@ -51,9 +51,9 @@ public class BaseTests
   public static final int dataPartitionBitSize = 8;
 
   // Selectors for domain and IP queries, queryIdentifier is the first entry for file generation
-  private static ArrayList<String> selectorsDomain = new ArrayList<>(
+  public static List<String> selectorsDomain = new ArrayList<>(
       Arrays.asList("s.t.u.net", "d.e.com", "r.r.r.r", "a.b.c.com", "something.else", "x.y.net"));
-  private static ArrayList<String> selectorsIP = new ArrayList<>(Arrays.asList("55.55.55.55",
"5.6.7.8", "10.20.30.40", "13.14.15.16", "21.22.23.24"));
+  public static List<String> selectorsIP = new ArrayList<>(Arrays.asList("55.55.55.55",
"5.6.7.8", "10.20.30.40", "13.14.15.16", "21.22.23.24"));
 
   // Encryption variables -- Paillier mechanisms are tested in the Paillier test code, so
these are fixed...
   public static final int hashBitSize = 12;

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/main/java/org/apache/pirk/test/utils/StandaloneQuery.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/pirk/test/utils/StandaloneQuery.java b/src/main/java/org/apache/pirk/test/utils/StandaloneQuery.java
index 847b18b..6eb27c5 100644
--- a/src/main/java/org/apache/pirk/test/utils/StandaloneQuery.java
+++ b/src/main/java/org/apache/pirk/test/utils/StandaloneQuery.java
@@ -48,26 +48,37 @@ import static org.junit.Assert.fail;
 public class StandaloneQuery
 {
   private static final Logger logger = LoggerFactory.getLogger(StandaloneQuery.class);
-
-  static String queryFileDomain = "qfDomain";
-  static String queryFileIP = "qfIP";
-
-  String testDataSchemaName = "testDataSchema";
-  String testQuerySchemaName = "testQuerySchema";
+  public static final String QUERY_SIDE_OUPUT_FILE_PREFIX = "querySideOut";
+
+  /**
+   * A helper method to create a querier from a query type string and a list of selectors.
Used in tests.
+   * @param queryType A string describing the query schema for this querier.
+   * @param selectors A list of selectors for the querier.
+   * @return A {@link Querier} representing the submitted information.
+   * @throws PIRException
+   * @throws InterruptedException
+   */
+  public static Querier createQuerier(String queryType, List<String> selectors) throws
PIRException, InterruptedException
+  {
+    Properties baseTestEncryptionProperties = EncryptionPropertiesBuilder.newBuilder().dataPartitionBitSize(BaseTests.dataPartitionBitSize)
+        .hashBitSize(BaseTests.hashBitSize).paillierBitSize(BaseTests.paillierBitSize).certainty(BaseTests.certainty)
+        .queryType(queryType).build();
+    return QuerierFactory.createQuerier(BaseTests.queryIdentifier, selectors, baseTestEncryptionProperties);
+  }
 
   // Base method to perform the query
   public static List<QueryResponseJSON> performStandaloneQuery(List<JSONObject>
dataElements, String queryType, List<String> selectors, int numThreads,
       boolean testFalsePositive) throws IOException, InterruptedException, PIRException
   {
+
     logger.info("Performing watchlisting: ");
 
     QuerySchema qSchema = QuerySchemaRegistry.get(queryType);
 
     // Create the necessary files
     LocalFileSystemStore storage = new LocalFileSystemStore();
-    String querySideOuputFilePrefix = "querySideOut";
-    File fileQuerier = File.createTempFile(querySideOuputFilePrefix + "-" + QuerierConst.QUERIER_FILETAG,
".txt");
-    File fileQuery = File.createTempFile(querySideOuputFilePrefix + "-" + QuerierConst.QUERY_FILETAG,
".txt");
+    File fileQuerier = File.createTempFile(QUERY_SIDE_OUPUT_FILE_PREFIX + "-" + QuerierConst.QUERIER_FILETAG,
".txt");
+    File fileQuery = File.createTempFile(QUERY_SIDE_OUPUT_FILE_PREFIX + "-" + QuerierConst.QUERY_FILETAG,
".txt");
     String responseFile = "encryptedResponse";
     File fileResponse = File.createTempFile(responseFile, ".txt");
     String finalResultsFile = "finalResultFile";
@@ -76,11 +87,7 @@ public class StandaloneQuery
     logger.info("fileQuerier = " + fileQuerier.getAbsolutePath() + " fileQuery  = " + fileQuery.getAbsolutePath()
+ " responseFile = "
         + fileResponse.getAbsolutePath() + " fileFinalResults = " + fileFinalResults.getAbsolutePath());
 
-    Properties baseTestEncryptionProperties = EncryptionPropertiesBuilder.newBuilder().dataPartitionBitSize(BaseTests.dataPartitionBitSize)
-        .hashBitSize(BaseTests.hashBitSize).paillierBitSize(BaseTests.paillierBitSize).certainty(BaseTests.certainty)
-        .queryType(queryType).build();
-
-    Querier querier = QuerierFactory.createQuerier(BaseTests.queryIdentifier, selectors,
baseTestEncryptionProperties);
+    Querier querier = createQuerier(queryType, selectors);
     logger.info("Completed encryption of the selectors - completed formation of the encrypted
query vectors:");
 
     // Dork with the embedSelectorMap to generate a false positive for the last valid selector
in selectors

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/test/java/org/apache/pirk/serialization/SerializationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pirk/serialization/SerializationTest.java b/src/test/java/org/apache/pirk/serialization/SerializationTest.java
index 8689d43..a44b7a9 100644
--- a/src/test/java/org/apache/pirk/serialization/SerializationTest.java
+++ b/src/test/java/org/apache/pirk/serialization/SerializationTest.java
@@ -18,35 +18,54 @@
  */
 package org.apache.pirk.serialization;
 
+import org.apache.pirk.querier.wideskies.Querier;
+import org.apache.pirk.response.wideskies.Response;
+import org.apache.pirk.test.utils.BaseTests;
+import org.apache.pirk.test.utils.Inputs;
+import org.apache.pirk.test.utils.StandaloneQuery;
+import org.apache.pirk.utils.SystemConfiguration;
+import org.apache.pirk.wideskies.standalone.StandaloneTest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.Serializable;
+import java.math.BigInteger;
 import java.util.Objects;
 import java.util.Random;
 
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
 public class SerializationTest
 {
-
+  private static final Logger logger = LoggerFactory.getLogger(SerializationTest.class);
+  
   @Rule
   public TemporaryFolder folder = new TemporaryFolder();
-
+  
   private static JsonSerializer jsonSerializer;
   private static JavaSerializer javaSerializer;
 
   @BeforeClass
   public static void setUp() throws Exception
   {
+    StandaloneTest.setup();
     jsonSerializer = new JsonSerializer();
     javaSerializer = new JavaSerializer();
   }
 
+  @AfterClass
+  public static void teardown() {
+    StandaloneTest.teardown();
+  }
+
   @Test
   public void testJsonSerDe() throws Exception
   {
@@ -75,6 +94,106 @@ public class SerializationTest
     Assert.assertTrue(deserializedDummyObject.equals(dummyRecord));
   }
 
+  @Test
+  public void testQuerierResponseSerializationDeserialization()
+  {
+    testQuerierResponseSerializationDeserialization(jsonSerializer);
+    testQuerierResponseSerializationDeserialization(javaSerializer);
+  }
+  
+  private void testQuerierResponseSerializationDeserialization(SerializationService service)

+  {
+    String initialAdHocSchema = SystemConfiguration.getProperty("pir.allowAdHocQuerySchemas",
"false");
+    String initialEmbedSchema = SystemConfiguration.getProperty("pir.embedQuerySchema", "false");
+    try
+    {
+      // Run tests without ad-hoc query schemas or embeded query schemas
+      SystemConfiguration.setProperty("pir.allowAdHocQuerySchemas", "false");
+      SystemConfiguration.setProperty("pir.embedQuerySchema", "false");
+      Querier querier = StandaloneQuery.createQuerier(Inputs.DNS_HOSTNAME_QUERY, BaseTests.selectorsDomain);
+      checkSerializeDeserialize(querier, service);
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_SRCIP_QUERY, BaseTests.selectorsIP);
+      checkSerializeDeserialize(querier, service);
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_IP_QUERY, BaseTests.selectorsIP);
+      checkSerializeDeserialize(querier, service);
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_NXDOMAIN_QUERY, BaseTests.selectorsDomain);
+      checkSerializeDeserialize(querier, service);
+
+      // Test with ad-hoc query schema but no embedded QuerySchema
+      SystemConfiguration.setProperty("pir.allowAdHocQuerySchemas", "true");
+      SystemConfiguration.setProperty("pir.embedQuerySchema", "false");
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_HOSTNAME_QUERY, BaseTests.selectorsDomain);
+      checkSerializeDeserialize(querier, service);
+
+      // Test with ad-hoc query schema and embedded query schema.
+      SystemConfiguration.setProperty("pir.allowAdHocQuerySchemas", "true");
+      SystemConfiguration.setProperty("pir.embedQuerySchema", "true");
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_HOSTNAME_QUERY, BaseTests.selectorsDomain);
+      checkSerializeDeserialize(querier, service);
+
+      // Test with embedded query schema but without ad-hoc query schemas.
+      SystemConfiguration.setProperty("pir.allowAdHocQuerySchemas", "false");
+      SystemConfiguration.setProperty("pir.embedQuerySchema", "true");
+      querier = StandaloneQuery.createQuerier(Inputs.DNS_HOSTNAME_QUERY, BaseTests.selectorsDomain);
+      checkSerializeDeserialize(querier, service);
+
+      // Create Response.
+      Response response = new Response(querier.getQuery().getQueryInfo());
+      for (Integer i = 0; i < 10; i++ )
+      {
+        response.addElement(i.intValue(), new BigInteger(i.toString()));
+      }
+      // Test response.
+      checkSerializeDeserialize(response, service);
+    } catch (Exception e)
+    {
+      logger.error("Threw an exception while creating queries.", e);
+      Assert.fail(e.toString());
+    } finally
+    {
+      SystemConfiguration.setProperty("pir.allowAdHocQuerySchemas", initialAdHocSchema);
+      SystemConfiguration.setProperty("pir.embedQuerySchema", initialEmbedSchema);
+    }
+  }
+
+  private void checkSerializeDeserialize(Querier querier, SerializationService service) throws
IOException
+  {
+    try
+    {
+      File fileQuerier = folder.newFile();
+      fileQuerier.deleteOnExit();
+      // Serialize Querier
+      service.write(new FileOutputStream(fileQuerier), querier);
+      // Deserialize Querier
+      Querier deserializedQuerier = service.read(new FileInputStream(fileQuerier), Querier.class);
+      // Check
+      Assert.assertTrue(querier.equals(deserializedQuerier));
+    } catch (IOException e)
+    {
+      logger.error("File operation error: ", e);
+      throw e;
+    }
+  }
+
+  private void checkSerializeDeserialize(Response response, SerializationService service)
throws IOException
+  {
+    try
+    {
+      File fileResponse = folder.newFile();
+      fileResponse.deleteOnExit();
+      // Serialize Response
+      service.write(new FileOutputStream(fileResponse), response);
+      // Deserialize Response
+      Response deserializedResponse = service.read(new FileInputStream(fileResponse), Response.class);
+      // Check
+      Assert.assertTrue(response.equals(deserializedResponse));
+    } catch (IOException e)
+    {
+      logger.error("File operation error: ", e);
+      throw e;
+    }
+  }
+
   private static class DummyRecord implements Serializable, Storable
   {
     private int id;
@@ -130,5 +249,4 @@ public class SerializationTest
       return Objects.hash(id, message);
     }
   }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-pirk/blob/2c928852/src/test/java/org/apache/pirk/wideskies/standalone/StandaloneTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/pirk/wideskies/standalone/StandaloneTest.java b/src/test/java/org/apache/pirk/wideskies/standalone/StandaloneTest.java
index cb65a60..8567059 100644
--- a/src/test/java/org/apache/pirk/wideskies/standalone/StandaloneTest.java
+++ b/src/test/java/org/apache/pirk/wideskies/standalone/StandaloneTest.java
@@ -75,6 +75,8 @@ public class StandaloneTest
   @AfterClass
   public static void teardown()
   {
+    // Reset the stoplist file property
+    SystemConfiguration.setProperty("pir.stopListFile", stopListFileProp);
     // Reset the schema properties and registries
     DataSchemaRegistry.clearRegistry();
     QuerySchemaRegistry.clearRegistry();
@@ -122,8 +124,5 @@ public class StandaloneTest
     // Run using a false positive
     SystemConfiguration.setProperty("pirTest.embedSelector", "true");
     BaseTests.testDNSHostnameQuery(dataElements, 1, true);
-
-    // Reset the stoplist file property
-    SystemConfiguration.setProperty("pir.stopListFile", stopListFileProp);
   }
 }



Mime
View raw message