use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class QuerierTest method testReceiveTimestamp.
@Test
public void testReceiveTimestamp() {
Long start = System.currentTimeMillis();
Query query = new Query();
query.setProjection(ProjectionUtils.makeProjection("field", "bid"));
query.setWindow(WindowUtils.makeReactiveWindow());
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RECORD_INJECT_TIMESTAMP, true);
config.validate();
query.configure(config);
Querier querier = make(Querier.Mode.ALL, query, config);
BulletRecord input = RecordBox.get().add("field", "foo").add("mid", "123").getRecord();
querier.consume(input);
Assert.assertTrue(querier.isClosed());
List<BulletRecord> records = querier.getRecords();
Assert.assertEquals(records.size(), 1);
BulletRecord actual = records.get(0);
Long end = System.currentTimeMillis();
Assert.assertEquals(size(actual), 2);
Assert.assertEquals(actual.get("bid"), "foo");
Long recordedTimestamp = (Long) actual.get(BulletConfig.DEFAULT_RECORD_INJECT_TIMESTAMP_KEY);
Assert.assertTrue(recordedTimestamp >= start);
Assert.assertTrue(recordedTimestamp <= end);
}
use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class QuerierTest method testMissingAggregationType.
@Test
public void testMissingAggregationType() {
Querier querier = new Querier("", "{ 'aggregation': { 'type': null }}", new BulletConfig());
Optional<List<BulletError>> errors = querier.initialize();
Assert.assertTrue(errors.isPresent());
Assert.assertEquals(errors.get().size(), 1);
Assert.assertEquals(errors.get().get(0), Aggregation.TYPE_NOT_SUPPORTED_ERROR);
}
use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class QuerierTest method testAdditiveWindowsDoNotResetInAllMode.
@Test
public void testAdditiveWindowsDoNotResetInAllMode() {
BulletConfig config = new BulletConfig();
RunningQuery runningQuery = makeCountQueryWithAllWindow(config, 2000);
Querier querier = new Querier(Querier.Mode.ALL, runningQuery, config);
querier.initialize();
Assert.assertFalse(querier.isClosed());
Assert.assertTrue(querier.shouldBuffer());
Assert.assertEquals(querier.getWindow().getClass(), AdditiveTumbling.class);
IntStream.range(0, 10).forEach(i -> querier.consume(RecordBox.get().getRecord()));
Assert.assertFalse(querier.isClosed());
List<BulletRecord> result = querier.getResult().getRecords();
Assert.assertEquals(result.size(), 1);
BulletRecord record = result.get(0);
Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 10L);
IntStream.range(0, 10).forEach(i -> querier.consume(RecordBox.get().getRecord()));
result = querier.getResult().getRecords();
Assert.assertEquals(result.size(), 1);
record = result.get(0);
Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 20L);
// This will not reset
querier.reset();
IntStream.range(0, 5).forEach(i -> querier.consume(RecordBox.get().getRecord()));
result = querier.getResult().getRecords();
Assert.assertEquals(result.size(), 1);
record = result.get(0);
Assert.assertEquals(record.get(GroupOperation.GroupOperationType.COUNT.getName()), 25L);
}
use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class QuerierTest method testRateLimiting.
@Test
public void testRateLimiting() throws Exception {
BulletConfig config = new BulletConfig();
config.set(BulletConfig.RATE_LIMIT_ENABLE, true);
config.set(BulletConfig.RATE_LIMIT_TIME_INTERVAL, 1);
config.set(BulletConfig.RATE_LIMIT_MAX_EMIT_COUNT, 1);
config.validate();
Querier querier = make(Querier.Mode.ALL, "", "{}", config);
Assert.assertFalse(querier.isExceedingRateLimit());
Assert.assertNull(querier.getRateLimitError());
IntStream.range(0, 1000).forEach(i -> querier.getRecords());
// To make sure it's time to check again
Thread.sleep(1);
Assert.assertTrue(querier.isExceedingRateLimit());
Assert.assertNotNull(querier.getRateLimitError());
}
use of com.yahoo.bullet.common.BulletConfig in project bullet-core by yahoo.
the class QuerierTest method testRawQueriesWithAllIncludeWindowsAreErrors.
@Test
public void testRawQueriesWithAllIncludeWindowsAreErrors() {
BulletConfig config = new BulletConfig();
Query query = new Query();
query.setWindow(WindowUtils.makeWindow(Window.Unit.TIME, 1, Window.Unit.ALL, null));
query.configure(config);
Querier querier = new Querier(new RunningQuery("", query), config);
Optional<List<BulletError>> errors = querier.initialize();
Assert.assertTrue(errors.isPresent());
Assert.assertEquals(errors.get(), singletonList(Query.NO_RAW_ALL));
}
Aggregations