use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testCategorizingAll.
@Test
public void testCategorizingAll() {
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);
QueryCategorizer categorizer = manager.categorize();
Assert.assertEquals(categorizer.getDone().size(), 0);
Assert.assertEquals(categorizer.getClosed().size(), 0);
Assert.assertEquals(categorizer.getRateLimited().size(), 0);
verify(querierA, times(1)).isDone();
verify(querierA, times(1)).isClosed();
verify(querierA, times(1)).isExceedingRateLimit();
verify(querierB, times(1)).isDone();
verify(querierB, times(1)).isClosed();
verify(querierB, times(1)).isExceedingRateLimit();
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class RunningQueryTest method testCreatingWithQuery.
@Test
public void testCreatingWithQuery() {
BulletConfig config = new BulletConfig();
Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), null);
query.configure(config);
RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, "bar"));
Assert.assertEquals(runningQuery.getId(), "foo");
Assert.assertNotNull(runningQuery.getQuery());
Assert.assertEquals(runningQuery.getQueryString(), "bar");
Assert.assertEquals(runningQuery.toString(), query.toString());
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class RunningQueryTest method testTimingOut.
@Test
public void testTimingOut() throws Exception {
BulletConfig config = new BulletConfig();
Query query = new Query(new Projection(), null, new Raw(null), null, new Window(), 1L);
query.configure(config);
RunningQuery runningQuery = new RunningQuery("foo", query, new Metadata(null, null));
// Sleep to make sure it's 1 ms
Thread.sleep(1);
Assert.assertTrue(runningQuery.isTimedOut());
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testPartitioning.
@Test
public void testPartitioning() {
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").getRecord();
BulletRecord recordB = RecordBox.get().add("A", "foo").add("B", "bar").getRecord();
BulletRecord recordC = RecordBox.get().getRecord();
Map<String, Querier> partitionA = manager.partition(recordA);
Map<String, Querier> partitionB = manager.partition(recordB);
Map<String, Querier> partitionC = manager.partition(recordC);
Assert.assertEquals(partitionA.size(), 2);
Assert.assertSame(partitionA.get("idA"), querierA);
Assert.assertSame(partitionA.get("idC"), querierC);
Assert.assertEquals(partitionB.size(), 3);
Assert.assertSame(partitionB.get("idA"), querierA);
Assert.assertSame(partitionB.get("idB"), querierB);
Assert.assertSame(partitionB.get("idC"), querierC);
Assert.assertEquals(partitionC.size(), 1);
Assert.assertSame(partitionC.get("idC"), querierC);
}
use of com.yahoo.bullet.query.Query in project bullet-core by yahoo.
the class QueryManagerTest method testAddingAndRemovingQueries.
@Test
public void testAddingAndRemovingQueries() {
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"));
Querier querierA = getQuerier(queryA);
Querier querierB = getQuerier(queryB);
Querier querierC = getQuerier(queryA);
Querier querierD = getQuerier(queryA);
Querier querierE = getQuerier(queryB);
manager.addQuery("idA", querierA);
manager.addQuery("idB", querierB);
manager.addQuery("idC", querierC);
manager.addQuery("idD", querierD);
manager.addQuery("idE", querierE);
Assert.assertSame(manager.getQuery("idA"), querierA);
Assert.assertSame(manager.getQuery("idC"), querierC);
Assert.assertSame(manager.getQuery("idD"), querierD);
Assert.assertSame(manager.getQuery("idB"), querierB);
Assert.assertSame(manager.getQuery("idE"), querierE);
Assert.assertTrue(manager.hasQuery("idA"));
Assert.assertFalse(manager.hasQuery("foo"));
Assert.assertEquals(manager.size(), 5);
Assert.assertNull(manager.removeAndGetQuery("fake"));
Assert.assertSame(manager.removeAndGetQuery("idC"), querierC);
Assert.assertEquals(manager.size(), 4);
List<Querier> removed = manager.removeAndGetQueries(new LinkedHashSet<>(asList("idE", "idB", "idC")));
Assert.assertEquals(removed.size(), 2);
Assert.assertSame(removed.get(0), querierE);
Assert.assertSame(removed.get(1), querierB);
Assert.assertEquals(manager.size(), 2);
Assert.assertNotNull(manager.getQuery("idA"));
Assert.assertNotNull(manager.getQuery("idD"));
Assert.assertNull(manager.getQuery("idB"));
Assert.assertNull(manager.getQuery("idC"));
Assert.assertNull(manager.getQuery("idE"));
Assert.assertEquals(manager.size(), 2);
manager.removeQueries(new HashSet<>(asList("idD", "idA")));
Assert.assertNull(manager.getQuery("idA"));
Assert.assertNull(manager.getQuery("idD"));
Assert.assertFalse(manager.hasQuery("idA"));
Assert.assertEquals(manager.size(), 0);
}
Aggregations