From 116946d5e94d1990b2e7ed15823b460713b1d120 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 29 Sep 2017 15:07:32 +0300 Subject: [PATCH] Added range field operations --- README.md | 3 +- .../java/integrationtest/PilosaClientIT.java | 11 +- .../java/com/pilosa/client/orm/Frame.java | 44 ++---- .../com/pilosa/client/orm/FrameOptions.java | 14 +- .../com/pilosa/client/orm/RangeField.java | 125 +++++++++++++----- .../com/pilosa/client/orm/RangeFieldInfo.java | 93 +++++++++++++ .../java/com/pilosa/client/orm/OrmTest.java | 74 +++++++++-- .../pilosa/client/orm/RangeFieldInfoTest.java | 98 ++++++++++++++ .../com/pilosa/client/orm/RangeFieldTest.java | 41 ++---- 9 files changed, 389 insertions(+), 114 deletions(-) create mode 100644 com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeFieldInfo.java create mode 100644 com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldInfoTest.java diff --git a/README.md b/README.md index aa2c2ec..3cb03d7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Java client for Pilosa high performance distributed bitmap index. * **Next**: * Added support for creating range encoded frames. - * Added `SetFieldValue`, `Sum` and `Xor` calls. + * Added `Xor` call. + * Added range field operations. * Added support for excluding bits or attributes from bitmap calls. In order to exclude bits, call `setExcludeBits(true)` in your `QueryOptions.Builder`. In order to exclude attributes, call `setExcludeAttributes(true)`. * Customizable CSV time stamp format. * **Deprecation** Row and column labels are deprecated, and will be removed in a future release of this library. Do not use `IndexOptions.Builder.setColumnLabel` and `FrameOptions.Builder.setRowLabel` methods for new code. See: https://github.com/pilosa/pilosa/issues/752 for more info. diff --git a/com.pilosa.client/src/integration-test/java/integrationtest/PilosaClientIT.java b/com.pilosa.client/src/integration-test/java/integrationtest/PilosaClientIT.java index 1730a09..4b14616 100644 --- a/com.pilosa.client/src/integration-test/java/integrationtest/PilosaClientIT.java +++ b/com.pilosa.client/src/integration-test/java/integrationtest/PilosaClientIT.java @@ -501,14 +501,17 @@ public void rangeFrameTest() throws IOException { client.query(this.index.batchQuery( frame.setBit(1, 10), frame.setBit(1, 100), - frame.setFieldValue(10, "foo", 11), - frame.setFieldValue(100, "foo", 15) + frame.field("foo").setValue(10, 11), + frame.field("foo").setValue(100, 15) )); - QueryResponse response = client.query(frame.sum(frame.bitmap(1), "foo")); + QueryResponse response = client.query(frame.field("foo").sum(frame.bitmap(1))); assertEquals(26, response.getResult().getSum()); assertEquals(2, response.getResult().getCount()); - } + response = client.query(frame.field("foo").lessThan(15)); + assertEquals(1, response.getResults().size()); + assertEquals(10, (long) response.getResult().getBitmap().getBits().get(0)); + } } @Test diff --git a/com.pilosa.client/src/main/java/com/pilosa/client/orm/Frame.java b/com.pilosa.client/src/main/java/com/pilosa/client/orm/Frame.java index b3d463f..4f84ab1 100644 --- a/com.pilosa.client/src/main/java/com/pilosa/client/orm/Frame.java +++ b/com.pilosa.client/src/main/java/com/pilosa/client/orm/Frame.java @@ -44,6 +44,7 @@ import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.HashMap; import java.util.Map; /** @@ -64,6 +65,7 @@ private Frame(Index index, String name, FrameOptions options) { this.options = options; this.columnLabel = index.getOptions().getColumnLabel(); this.rowLabel = options.getRowLabel(); + this.fields = new HashMap<>(); } /** @@ -379,33 +381,18 @@ public PqlBaseQuery setRowAttrs(long rowID, Map attributes) { } /** - * Creates a SetFieldValue query. - * - * @param columnID column ID - * @param field the field to set - * @param value the value to assign to the field - * @return a PQL query - * @see SetFieldValue Query - */ - public PqlBaseQuery setFieldValue(long columnID, String field, long value) { - String qry = String.format("SetFieldValue(frame='%s', %s=%d, %s=%d)", - this.name, this.columnLabel, columnID, field, value); - return this.index.pqlQuery(qry); - } - - /** - * Creates a SumReduce query. - *

- * The frame for this query should have fields set. - *

- * - * @param bitmap The bitmap query to use. - * @param field The field to calculate the sum for. - * @return a PQL query - * @see Sum Query + * Returns a RangeField object with the given name + * @param name field name + * @return RangeField object */ - public PqlBaseQuery sum(PqlBitmapQuery bitmap, String field) { - return rangeQuery("Sum", bitmap, field); + public RangeField field(String name) { + RangeField field = this.fields.get(name); + if (field == null) { + Validator.ensureValidLabel(name); + field = new RangeField(this, name); + this.fields.put(name, field); + } + return field; } @Override @@ -429,10 +416,6 @@ public int hashCode() { .toHashCode(); } - private PqlBaseQuery rangeQuery(String call, PqlBitmapQuery bitmap, String field) { - return this.index.pqlQuery(String.format("%s(%s, frame='%s', field='%s')", call, bitmap.serialize(), this.name, field)); - } - private final static DateFormat fmtDate = new SimpleDateFormat("yyyy-MM-dd"); private final static DateFormat fmtTime = new SimpleDateFormat("HH:mm"); private String name; @@ -440,5 +423,6 @@ private PqlBaseQuery rangeQuery(String call, PqlBitmapQuery bitmap, String field private FrameOptions options; private String rowLabel; private String columnLabel; + private Map fields; private ObjectMapper mapper = new ObjectMapper(); } diff --git a/com.pilosa.client/src/main/java/com/pilosa/client/orm/FrameOptions.java b/com.pilosa.client/src/main/java/com/pilosa/client/orm/FrameOptions.java index a07712c..0edb673 100644 --- a/com.pilosa.client/src/main/java/com/pilosa/client/orm/FrameOptions.java +++ b/com.pilosa.client/src/main/java/com/pilosa/client/orm/FrameOptions.java @@ -142,7 +142,7 @@ public Builder setCacheSize(int cacheSize) { * @see Pilosa Data Model: Frame */ public Builder addIntField(String name, long min, long max) { - this.fields.put(name, RangeField.intField(name, min, max)); + this.fields.put(name, RangeFieldInfo.intField(name, min, max)); return this; } @@ -162,7 +162,7 @@ public FrameOptions build() { private boolean inverseEnabled = false; private CacheType cacheType = CacheType.DEFAULT; private int cacheSize = 0; - private Map fields = new HashMap<>(); + private Map fields = new HashMap<>(); } @@ -232,8 +232,8 @@ public String toString() { if (this.fields.size() > 0) { builder.append(",\"rangeEnabled\":true"); builder.append(",\"fields\":["); - Iterator> iter = this.fields.entrySet().iterator(); - Map.Entry entry = iter.next(); + Iterator> iter = this.fields.entrySet().iterator(); + Map.Entry entry = iter.next(); builder.append(entry.getValue()); while (iter.hasNext()) { entry = iter.next(); @@ -278,13 +278,13 @@ public int hashCode() { private FrameOptions(final String rowLabel, final TimeQuantum timeQuantum, final boolean inverseEnabled, final CacheType cacheType, final int cacheSize, - final Map fields) { + final Map fields) { this.rowLabel = rowLabel; this.timeQuantum = timeQuantum; this.inverseEnabled = inverseEnabled; this.cacheType = cacheType; this.cacheSize = cacheSize; - this.fields = (fields != null) ? fields : new HashMap(); + this.fields = (fields != null) ? fields : new HashMap(); } private final String rowLabel; @@ -292,5 +292,5 @@ private FrameOptions(final String rowLabel, final TimeQuantum timeQuantum, private final boolean inverseEnabled; private final CacheType cacheType; private final int cacheSize; - private final Map fields; + private final Map fields; } diff --git a/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeField.java b/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeField.java index 6277fc4..299cdaf 100644 --- a/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeField.java +++ b/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeField.java @@ -34,36 +34,90 @@ package com.pilosa.client.orm; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.pilosa.client.Validator; -import com.pilosa.client.exceptions.ValidationException; import org.apache.commons.lang3.builder.HashCodeBuilder; -import java.util.HashMap; -import java.util.Map; - public class RangeField { - public static RangeField intField(String name, long min, long max) { - Validator.ensureValidLabel(name); - if (max <= min) { - throw new ValidationException("Max should be greater than min for int fields"); - } - Map properties = new HashMap<>(4); - properties.put("name", name); - properties.put("type", "int"); - properties.put("min", min); - properties.put("max", max); - return new RangeField(properties); + /** + * Creates a Range query with less than (<) condition. + * + * @param n The value to compare + * @return a PQL query + */ + public PqlBitmapQuery lessThan(long n) { + return binaryOperation("<", n); } - @Override - public String toString() { - ObjectMapper mapper = new ObjectMapper(); - try { - return mapper.writeValueAsString(this.properties); - } catch (Exception ex) { - throw new ValidationException("Field properties weren't converted to JSON", ex); - } + /** + * Creates a Range query with less than or equal (<=) condition. + * + * @param n The value to compare + * @return a PQL query + */ + public PqlBitmapQuery lessThanOrEqual(long n) { + return binaryOperation("<=", n); + } + + /** + * Creates a Range query with greater than (>) condition. + * + * @param n The value to compare + * @return a PQL query + */ + public PqlBitmapQuery greaterThan(long n) { + return binaryOperation(">", n); + } + + /** + * Creates a Range query with greater than or equal (>=) condition. + * + * @param n The value to compare + * @return a PQL query + */ + public PqlBitmapQuery greaterThanOrEqual(long n) { + return binaryOperation(">=", n); + } + + /** + * Creates a Range query with between (><) condition. + * + * @param a Closed range start + * @param b Closed range end + * @return a PQL query + */ + public PqlBitmapQuery between(long a, long b) { + String qry = String.format("Range(frame='%s', %s >< [%d,%d])", + frame.getName(), this.name, a, b); + return this.index.pqlBitmapQuery(qry); + } + + /** + * Creates a Sum query. + *

+ * The frame for this query should have fields set. + *

+ * + * @param bitmap The bitmap query to use. + * @return a PQL query + * @see Sum Query + */ + public PqlBaseQuery sum(PqlBitmapQuery bitmap) { + String qry = String.format("Sum(%s, frame='%s', field='%s')", + bitmap.serialize(), frame.getName(), name); + return this.index.pqlQuery(qry); + } + + /** + * Creates a SetFieldValue query. + * + * @param columnID column ID + * @param value the value to assign to the field + * @return a PQL query + * @see SetFieldValue Query + */ + public PqlBaseQuery setValue(long columnID, long value) { + String qry = String.format("SetFieldValue(frame='%s', %s=%d, %s=%d)", + frame.getName(), this.index.getOptions().getColumnLabel(), columnID, name, value); + return this.index.pqlQuery(qry); } @Override @@ -75,19 +129,30 @@ public boolean equals(Object obj) { return true; } RangeField rhs = (RangeField) obj; - return rhs.properties.equals(this.properties); + return rhs.name.equals(this.name); } @Override public int hashCode() { return new HashCodeBuilder(31, 47) - .append(this.properties) + .append(this.name) .toHashCode(); } - RangeField(Map properties) { - this.properties = properties; + + RangeField(Frame frame, String name) { + this.index = frame.getIndex(); + this.frame = frame; + this.name = name; + } + + private PqlBitmapQuery binaryOperation(String op, long n) { + String qry = String.format("Range(frame='%s', %s %s %d)", + frame.getName(), this.name, op, n); + return this.index.pqlBitmapQuery(qry); } - private final Map properties; + private Index index; + private Frame frame; + private String name; } diff --git a/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeFieldInfo.java b/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeFieldInfo.java new file mode 100644 index 0000000..49a5a1b --- /dev/null +++ b/com.pilosa.client/src/main/java/com/pilosa/client/orm/RangeFieldInfo.java @@ -0,0 +1,93 @@ +/* + * Copyright 2017 Pilosa Corp. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +package com.pilosa.client.orm; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.pilosa.client.Validator; +import com.pilosa.client.exceptions.ValidationException; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.util.HashMap; +import java.util.Map; + +public class RangeFieldInfo { + public static RangeFieldInfo intField(String name, long min, long max) { + Validator.ensureValidLabel(name); + if (max <= min) { + throw new ValidationException("Max should be greater than min for int fields"); + } + Map properties = new HashMap<>(4); + properties.put("name", name); + properties.put("type", "int"); + properties.put("min", min); + properties.put("max", max); + return new RangeFieldInfo(properties); + } + + @Override + public String toString() { + ObjectMapper mapper = new ObjectMapper(); + try { + return mapper.writeValueAsString(this.properties); + } catch (Exception ex) { + throw new ValidationException("Field properties weren't converted to JSON", ex); + } + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof RangeFieldInfo)) { + return false; + } + if (obj == this) { + return true; + } + RangeFieldInfo rhs = (RangeFieldInfo) obj; + return rhs.properties.equals(this.properties); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(31, 47) + .append(this.properties) + .toHashCode(); + } + + RangeFieldInfo(Map properties) { + this.properties = properties; + } + + private final Map properties; +} diff --git a/com.pilosa.client/src/test/java/com/pilosa/client/orm/OrmTest.java b/com.pilosa.client/src/test/java/com/pilosa/client/orm/OrmTest.java index 218364d..3983735 100644 --- a/com.pilosa.client/src/test/java/com/pilosa/client/orm/OrmTest.java +++ b/com.pilosa.client/src/test/java/com/pilosa/client/orm/OrmTest.java @@ -36,6 +36,7 @@ import com.pilosa.client.UnitTest; import com.pilosa.client.exceptions.PilosaException; +import com.pilosa.client.exceptions.ValidationException; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -307,16 +308,6 @@ public void topNTest() { q4.serialize()); } - @Test - public void sumTest() { - PqlBitmapQuery b = collabFrame.bitmap(42); - PqlQuery q1 = sampleFrame.sum(b, "foo"); - assertEquals( - "Sum(Bitmap(project=42, frame='collaboration'), frame='sample-frame', field='foo')", - q1.serialize() - ); - } - @Test(expected = PilosaException.class) public void topNInvalidValuesTest() { sampleFrame.topN(5, sampleFrame.bitmap(2), "category", 80, new Object()); @@ -384,10 +375,67 @@ public void inverseBitmapFailsIfNotEnabledTest() { } @Test - public void setFieldValueTest() { - PqlQuery q = collabFrame.setFieldValue(50, "foo", 15); + public void fieldLessThanTest() { + PqlQuery q = sampleFrame.field("foo").lessThan(10); + assertEquals( + "Range(frame='sample-frame', foo < 10)", + q.serialize()); + } + + @Test + public void fieldLessThanOrEqualTest() { + PqlQuery q = sampleFrame.field("foo").lessThanOrEqual(10); + assertEquals( + "Range(frame='sample-frame', foo <= 10)", + q.serialize()); + + } + + @Test + public void fieldGreaterThanTest() { + PqlQuery q = sampleFrame.field("foo").greaterThan(10); + assertEquals( + "Range(frame='sample-frame', foo > 10)", + q.serialize()); + + } + + @Test + public void fieldGreaterThanOrEqualTest() { + PqlQuery q = sampleFrame.field("foo").greaterThanOrEqual(10); assertEquals( - "SetFieldValue(frame='collaboration', user=50, foo=15)", + "Range(frame='sample-frame', foo >= 10)", q.serialize()); + + } + + @Test + public void fieldBetweenTest() { + PqlQuery q = sampleFrame.field("foo").between(10, 20); + assertEquals( + "Range(frame='sample-frame', foo >< [10,20])", + q.serialize()); + + } + + @Test + public void fieldSumTest() { + PqlQuery q = sampleFrame.field("foo").sum(sampleFrame.bitmap(10)); + assertEquals( + "Sum(Bitmap(rowID=10, frame='sample-frame'), frame='sample-frame', field='foo')", + q.serialize()); + } + + @Test + public void fieldSetValueTest() { + PqlQuery q = sampleFrame.field("foo").setValue(10, 20); + assertEquals( + "SetFieldValue(frame='sample-frame', columnID=10, foo=20)", + q.serialize()); + } + + @Test(expected = ValidationException.class) + public void invalidFieldTest() { + sampleFrame.field("??foo"); } } diff --git a/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldInfoTest.java b/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldInfoTest.java new file mode 100644 index 0000000..35019f4 --- /dev/null +++ b/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldInfoTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2017 Pilosa Corp. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +package com.pilosa.client.orm; + +import com.pilosa.client.UnitTest; +import com.pilosa.client.exceptions.PilosaException; +import com.pilosa.client.exceptions.ValidationException; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +@Category(UnitTest.class) +public class RangeFieldInfoTest { + @Test + public void testEqualsFailsWithOtherObject() { + RangeFieldInfo field = RangeFieldInfo.intField("foo", 10, 20); + @SuppressWarnings("EqualsBetweenInconvertibleTypes") + boolean e = field.equals("foo"); + assertFalse(e); + } + + @Test + public void testEqualsSameObject() { + RangeFieldInfo field = RangeFieldInfo.intField("foo", -10, 1000); + assertEquals(field, field); + } + + @Test + public void testEquals() { + RangeFieldInfo field1 = RangeFieldInfo.intField("bar", -10, 1000); + RangeFieldInfo field2 = RangeFieldInfo.intField("bar", -10, 1000); + assertTrue(field1.equals(field2)); + } + + @Test + public void testHashCode() { + RangeFieldInfo field1 = RangeFieldInfo.intField("foo", -10, 1000); + RangeFieldInfo field2 = RangeFieldInfo.intField("foo", -10, 1000); + assertEquals(field1.hashCode(), field2.hashCode()); + } + + @Test(expected = ValidationException.class) + public void testInvalidProperties() { + Map properties = new HashMap<>(1); + properties.put("invalid", new ThrowsException()); + RangeFieldInfo field = new RangeFieldInfo(properties); + String f = field.toString(); + System.out.println(f); + } + + @Test(expected = PilosaException.class) + public void testMaxGreaterThanMin() { + RangeFieldInfo.intField("foo", 10, 9); + } +} + +class ThrowsException { + @Override + public String toString() { + throw new RuntimeException("mock"); + } +} \ No newline at end of file diff --git a/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldTest.java b/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldTest.java index 8d9bd4c..f9263ad 100644 --- a/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldTest.java +++ b/com.pilosa.client/src/test/java/com/pilosa/client/orm/RangeFieldTest.java @@ -35,21 +35,17 @@ package com.pilosa.client.orm; import com.pilosa.client.UnitTest; -import com.pilosa.client.exceptions.PilosaException; -import com.pilosa.client.exceptions.ValidationException; import org.junit.Test; import org.junit.experimental.categories.Category; -import java.util.HashMap; -import java.util.Map; - import static org.junit.Assert.*; @Category(UnitTest.class) public class RangeFieldTest { + @Test public void testEqualsFailsWithOtherObject() { - RangeField field = RangeField.intField("foo", 10, 20); + RangeField field = frame.field("myfield"); @SuppressWarnings("EqualsBetweenInconvertibleTypes") boolean e = field.equals("foo"); assertFalse(e); @@ -57,42 +53,29 @@ public void testEqualsFailsWithOtherObject() { @Test public void testEqualsSameObject() { - RangeField field = RangeField.intField("foo", -10, 1000); + RangeField field = frame.field("myfield"); assertEquals(field, field); } @Test public void testEquals() { - RangeField field1 = RangeField.intField("bar", -10, 1000); - RangeField field2 = RangeField.intField("bar", -10, 1000); + RangeField field1 = frame.field("myfield"); + RangeField field2 = new RangeField(frame, "myfield"); assertTrue(field1.equals(field2)); } @Test public void testHashCode() { - RangeField field1 = RangeField.intField("foo", -10, 1000); - RangeField field2 = RangeField.intField("foo", -10, 1000); + RangeField field1 = frame.field("myfield"); + RangeField field2 = frame.field("myfield"); assertEquals(field1.hashCode(), field2.hashCode()); } - @Test(expected = ValidationException.class) - public void testInvalidProperties() { - Map properties = new HashMap<>(1); - properties.put("invalid", new ThrowsException()); - RangeField field = new RangeField(properties); - String f = field.toString(); - System.out.println(f); + static { + Schema schema = Schema.defaultSchema(); + Index index = schema.index("myindex"); + frame = index.frame("myframe"); } - @Test(expected = PilosaException.class) - public void testMaxGreaterThanMin() { - RangeField.intField("foo", 10, 9); - } + private static Frame frame; } - -class ThrowsException { - @Override - public String toString() { - throw new RuntimeException("mock"); - } -} \ No newline at end of file