use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testQuerySeeingStatistics.
@Test
public void testQuerySeeingStatistics() {
QueryManager manager = new QueryManager(getEqualityPartitionerConfig("A", "B"));
Query queryA = getQuery(ImmutablePair.of("A", "foo"));
Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
Query queryC = getQuery();
Querier querierA = getQuerier(queryA);
Querier querierB = getQuerier(queryB);
Querier querierC = getQuerier(queryC);
manager.addQuery("idA", querierA);
manager.addQuery("idB", querierB);
manager.addQuery("idC", querierC);
BulletRecord recordA = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
BulletRecord recordB = RecordBox.get().add("A", "foo").getRecord();
BulletRecord recordC = RecordBox.get().getRecord();
Map<QueryManager.PartitionStat, Object> stats;
manager.categorize(recordA);
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 3L);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 3L);
manager.categorize(recordB);
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 5L);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 6L);
manager.categorize(recordC);
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.ACTUAL_QUERIES_SEEN), 6L);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.EXPECTED_QUERIES_SEEN), 9L);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testCategorizingNoPartitioning.
@Test
public void testCategorizingNoPartitioning() {
QueryManager manager = new QueryManager(new BulletConfig());
Query queryA = getQuery(ImmutablePair.of("A", "foo"));
Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
Querier querierA = getQuerier(queryA);
Querier querierB = getQuerier(queryB);
manager.addQuery("idA", querierA);
manager.addQuery("idB", querierB);
BulletRecord recordA = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
BulletRecord recordB = RecordBox.get().add("A", "foo").getRecord();
QueryCategorizer categorizer = manager.categorize(recordA);
Assert.assertEquals(categorizer.getDone().size(), 0);
Assert.assertEquals(categorizer.getClosed().size(), 0);
Assert.assertEquals(categorizer.getRateLimited().size(), 0);
verify(querierA, times(1)).consume(recordA);
verify(querierB, times(1)).consume(recordA);
categorizer = manager.categorize(recordB);
Assert.assertEquals(categorizer.getDone().size(), 0);
Assert.assertEquals(categorizer.getClosed().size(), 0);
Assert.assertEquals(categorizer.getRateLimited().size(), 0);
verify(querierA, times(1)).consume(recordB);
verify(querierB, times(1)).consume(recordB);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method addQuerier.
private static void addQuerier(QueryManager manager, int i, int j, Map<String, Querier> queriers) {
String value = String.valueOf(i);
String id = String.valueOf((i * 100) + j);
Query query = getQuery(ImmutablePair.of("A", value));
Querier querier = getQuerier(query);
queriers.put(id, querier);
manager.addQuery(id, querier);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testPartitionRemoval.
@Test
public void testPartitionRemoval() {
QueryManager manager = new QueryManager(getEqualityPartitionerConfig("A", "B"));
Query queryA = getQuery(ImmutablePair.of("A", "foo"));
Query queryB = getQuery(ImmutablePair.of("A", "foo"), ImmutablePair.of("B", "bar"));
Query queryC = getQuery();
manager.addQuery("idA", getQuerier(queryA));
manager.addQuery("idB", getQuerier(queryB));
manager.addQuery("idC", getQuerier(queryC));
manager.addQuery("idD", getQuerier(queryC));
Map<QueryManager.PartitionStat, Object> stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 4);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 3);
manager.removeAndGetQuery("idA");
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 3);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 2);
manager.removeAndGetQuery("idB");
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 2);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 1);
manager.removeAndGetQuery("idD");
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 1);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 1);
manager.removeAndGetQuery("idC");
stats = manager.getStats();
Assert.assertEquals(stats.get(QueryManager.PartitionStat.QUERY_COUNT), 0);
Assert.assertEquals(stats.get(QueryManager.PartitionStat.PARTITION_COUNT), 0);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class PubSubMessageTest method testReadingDataAsDifferentTypes.
@Test
public void testReadingDataAsDifferentTypes() {
String string = getRandomString();
byte[] bytes = getRandomBytes();
Query query = new Query(new Projection(), null, new Raw(1), null, new Window(), Long.MAX_VALUE);
PubSubMessage message;
message = new PubSubMessage("foo", string);
Assert.assertEquals(message.getContent(), string);
Assert.assertEquals(message.getContentAsString(), string);
message = new PubSubMessage("foo", bytes);
Assert.assertEquals(message.getContent(), bytes);
Assert.assertEquals(message.getContentAsByteArray(), bytes);
message = new PubSubMessage("foo", query);
Assert.assertSame(message.getContent(), query);
Assert.assertSame(message.getContentAsQuery(), query);
}
Aggregations