SaltyRowKeyBuilder implements RowKeyBuilder { @Override public List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long start, long end) { long max = Math.max(start, end); start = Math.min(start, end); end = max; return ProfilePeriod.visitPeriods( start , end , periodDurationMillis , TimeUnit.MILLISECONDS , Optional.empty() , period -> rowKey(profile, entity, period, groups) ); } SaltyRowKeyBuilder();  SaltyRowKeyBuilder(int saltDivisor, long duration, TimeUnit units); @Override List<byte[]> rowKeys(String profile, String entity, List<Object> groups, long start, long end); @Override List<byte[]> rowKeys(String profile, String entity, List<Object> groups, Iterable<ProfilePeriod> periods); @Override byte[] rowKey(ProfileMeasurement m); byte[] rowKey(String profile, String entity, ProfilePeriod period, List<Object> groups); byte[] rowKey(String profile, String entity, long period, List<Object> groups); static byte[] getSalt(ProfilePeriod period, int saltDivisor); static byte[] getSalt(long period, int saltDivisor); void withPeriodDuration(long duration, TimeUnit units); void setSaltDivisor(int saltDivisor);  }
@Test public void testRowKeys() { int hoursAgo = 1; List<Object> groups = Collections.emptyList(); rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits); long now = System.currentTimeMillis(); long oldest = now - TimeUnit.HOURS.toMillis(hoursAgo); ProfileMeasurement m = new ProfileMeasurement() .withProfileName("profile") .withEntity("entity") .withPeriod(oldest, periodDuration, periodUnits) .withProfileValue(22); List<byte[]> expectedKeys = new ArrayList<>(); for (int i=0; i<(hoursAgo * 4)+1; i++) { byte[] rk = rowKeyBuilder.rowKey(m); expectedKeys.add(rk); ProfilePeriod next = m.getPeriod().next(); m = new ProfileMeasurement() .withProfileName("profile") .withEntity("entity") .withPeriod(next.getStartTimeMillis(), periodDuration, periodUnits); } List<byte[]> actualKeys = rowKeyBuilder.rowKeys(measurement.getProfileName(), measurement.getEntity(), groups, oldest, now); for(int i=0; i<actualKeys.size(); i++) { byte[] actual = actualKeys.get(i); byte[] expected = expectedKeys.get(i); assertThat(actual, equalTo(expected)); } }