}
public void test3AggregatesIntegrationTest() throws Exception {
final CompositeActivityValues inMemoryColumnData1 = CompositeActivityManager.cachedInstances.get(1).activityValues;
final CompositeActivityValues inMemoryColumnData2 = CompositeActivityManager.cachedInstances.get(2).activityValues;
final TimeAggregatedActivityValues timeAggregatedActivityValues1 = clear(inMemoryColumnData1);
final TimeAggregatedActivityValues timeAggregatedActivityValues2 = clear(inMemoryColumnData2);
for (ActivityIntValues activityIntValues : timeAggregatedActivityValues1.getValuesMap().values()) {
assertEquals(0, activityIntValues.getIntValue(0));
}
for (ActivityIntValues activityIntValues : timeAggregatedActivityValues2.getValuesMap().values()) {
for (int i = 0; i < activityIntValues.getFieldValues().length; i ++) {
assertEquals("" + i, 0, activityIntValues.getFieldValues()[i]);
}
}
int initialTime = Clock.getCurrentTimeInMinutes();
for (int i = 0; i < 10; i++) {
final int uid = i;
Clock.setPredefinedTimeInMinutes(Clock.getCurrentTimeInMinutes() + 1);
for (int j = 0; j < 10 - i; j ++) {
FileDataProviderWithMocks.add(new JSONObject().put("id", j).put(SenseiSchema.EVENT_TYPE_FIELD, SenseiSchema.EVENT_TYPE_UPDATE).put("likes", "+1"));
expectedVersion++;
}
syncWithVersion(expectedVersion);
}
String req = "{\"selections\": [{\"range\": {\"aggregated-likes:2w\": {\"from\": 8, \"include_lower\": true}}}], \"sort\":[{\"aggregated-likes:2w\":\"desc\"}]}";
JSONObject res = TestSensei.search(new JSONObject(req));
JSONArray hits = res.getJSONArray("hits");
assertEquals(Integer.parseInt(hits.getJSONObject(0).getJSONArray("aggregated-likes:2w").getString(0)), 10);
assertEquals(Integer.parseInt(hits.getJSONObject(1).getJSONArray("aggregated-likes:2w").getString(0)), 9);
assertEquals(Integer.parseInt(hits.getJSONObject(2).getJSONArray("aggregated-likes:2w").getString(0)), 8);
Clock.setPredefinedTimeInMinutes(initialTime + 11);
timeAggregatedActivityValues1.getAggregatesUpdateJob().run();
timeAggregatedActivityValues2.getAggregatesUpdateJob().run();
req = "{ \"sort\":[{\"aggregated-likes:5m\":\"desc\"}]}";
res = TestSensei.search(new JSONObject(req));
hits = res.getJSONArray("hits");
assertEquals(Integer.parseInt(hits.getJSONObject(0).getJSONArray("aggregated-likes:5m").getString(0)), 4);
assertEquals(Integer.parseInt(hits.getJSONObject(1).getJSONArray("aggregated-likes:5m").getString(0)), 3);
assertEquals(Integer.parseInt(hits.getJSONObject(2).getJSONArray("aggregated-likes:5m").getString(0)), 2);
assertEquals(Integer.parseInt(hits.getJSONObject(0).getJSONArray("aggregated-likes:15m").getString(0)), 10);
Clock.setPredefinedTimeInMinutes(initialTime + 20);
timeAggregatedActivityValues1.getAggregatesUpdateJob().run();
timeAggregatedActivityValues2.getAggregatesUpdateJob().run();
req = "{ \"sort\":[{\"aggregated-likes:15m\":\"desc\"}]}";
res = TestSensei.search(new JSONObject(req));
hits = res.getJSONArray("hits");