@Test public void testSingleSet() { Constraints c = emptyConstraints.partitionedBy(id) .with("component", "com.company.Main"); Marker main = new Marker.Builder("id_component", "com.company.Main").build(); MarkerRange actual = Iterables.getOnlyElement(c.toKeyRanges()); Assert.assertEquals(main, actual.getStart().getBound()); Assert.assertEquals(main, actual.getEnd().getBound()); Assert.assertEquals(new MarkerRange(idCmp).of(main), actual); c = emptyConstraints.partitionedBy(id).with("component", "com.company.Main", "com.company.SomeClass"); Marker sc = new Marker.Builder("id_component", "com.company.SomeClass").build(); assertIterableEquals( Sets.newHashSet( new MarkerRange(idCmp).of(main), new MarkerRange(idCmp).of(sc)), c.toKeyRanges()); }
@Test @SuppressWarnings("unchecked") public void testGroupSet() { String[] ids = new String[]{ UUID.randomUUID().toString(), UUID.randomUUID().toString()}; FieldPartitioner hashFunc = Accessor.getDefault().getFieldPartitioners(hash).get(0); Constraints c = emptyConstraints.partitionedBy(hash).with("id", ids[0]); Marker marker0 = new Marker.Builder() .add("id_hash", hashFunc.apply(ids[0])).add("id_copy", ids[0]).build(); MarkerRange actual = Iterables.getOnlyElement(c.toKeyRanges()); Assert.assertEquals(marker0, actual.getStart().getBound()); Assert.assertEquals(marker0, actual.getEnd().getBound()); c = emptyConstraints.partitionedBy(hash).with("id", (Object[]) ids); Marker marker1 = new Marker.Builder() .add("id_hash", hashFunc.apply(ids[1])).add("id_copy", ids[1]).build(); assertIterableEquals( Sets.newHashSet( new MarkerRange(hashCmp).of(marker0), new MarkerRange(hashCmp).of(marker1)), c.toKeyRanges()); }
@Test public void testTimeSet() { Long[] timestamps = new Long[] { 1379020547042L, // Thu Sep 12 14:15:47 PDT 2013 1381612547042L, // Sat Oct 12 14:15:47 PDT 2013 1384204547042L // Mon Nov 11 13:15:47 PST 2013 }; Constraints c = emptyConstraints.partitionedBy(time) .with("timestamp", (Object[]) timestamps); Marker sep = new Marker.Builder().add("year", 2013).add("month", 9).add("day", 12).build(); Marker oct = new Marker.Builder().add("year", 2013).add("month", 10).add("day", 12).build(); Marker nov = new Marker.Builder().add("year", 2013).add("month", 11).add("day", 11).build(); assertIterableEquals(Sets.newHashSet( new MarkerRange(timeCmp).of(sep), new MarkerRange(timeCmp).of(oct), new MarkerRange(timeCmp).of(nov)), c.toKeyRanges()); }