use of org.hypertrace.entity.data.service.v1.Query in project packages-jpl by SWI-Prolog.
the class TestJUnit method testVariableBinding1.
public void testVariableBinding1() {
Term lhs = new Compound("p", new Term[] { new Variable("X"), new Variable("Y") });
Term rhs = new Compound("p", new Term[] { new Atom("a"), new Atom("b") });
Term goal = new Compound("=", new Term[] { lhs, rhs });
Map<String, Term> soln = new Query(goal).oneSolution();
assertTrue("two Variables with different names can bind to distinct atoms", soln != null && (soln.get("X")).name().equals("a") && (soln.get("Y")).name().equals("b"));
}
use of org.hypertrace.entity.data.service.v1.Query in project beam by apache.
the class DatastoreV1Test method readFnTest.
/**
* Helper function to run a test reading from a {@link ReadFn}.
*/
private void readFnTest(int numEntities) throws Exception {
// An empty query to read entities.
Query query = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(numEntities)).build();
// Use mockResponseForQuery to generate results.
when(mockDatastore.runQuery(any(RunQueryRequest.class))).thenAnswer(invocationOnMock -> {
Query q = ((RunQueryRequest) invocationOnMock.getArguments()[0]).getQuery();
return mockResponseForQuery(q);
});
ReadFn readFn = new ReadFn(V_1_OPTIONS, mockDatastoreFactory);
DoFnTester<Query, Entity> doFnTester = DoFnTester.of(readFn);
/**
* Although Datastore client is marked transient in {@link ReadFn}, when injected through mock
* factory using a when clause for unit testing purposes, it is not serializable because it
* doesn't have a no-arg constructor. Thus disabling the cloning to prevent the test object from
* being serialized.
*/
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
List<Entity> entities = doFnTester.processBundle(query);
int expectedNumCallsToRunQuery = (int) Math.ceil((double) numEntities / QUERY_BATCH_LIMIT);
verify(mockDatastore, times(expectedNumCallsToRunQuery)).runQuery(any(RunQueryRequest.class));
// Validate the number of results.
assertEquals(numEntities, entities.size());
}
use of org.hypertrace.entity.data.service.v1.Query in project beam by apache.
the class DatastoreV1Test method testReadValidationFailsQueryLimitNegative.
@Test
public void testReadValidationFailsQueryLimitNegative() throws Exception {
Query invalidLimit = Query.newBuilder().setLimit(Int32Value.newBuilder().setValue(-5)).build();
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Invalid query limit -5: must be positive");
DatastoreIO.v1().read().withQuery(invalidLimit);
}
use of org.hypertrace.entity.data.service.v1.Query in project beam by apache.
the class V1ReadIT method testE2EV1Read.
/**
* An end-to-end test for {@link DatastoreV1.Read#withQuery(Query)}
*
* <p>Write some test entities to datastore and then run a pipeline that reads and counts the
* total number of entities. Verify that the count matches the number of entities written.
*/
@Test
public void testE2EV1Read() throws Exception {
// Read from datastore
Query query = V1TestUtil.makeAncestorKindQuery(options.getKind(), options.getNamespace(), ancestor);
DatastoreV1.Read read = DatastoreIO.v1().read().withProjectId(project).withQuery(query).withNamespace(options.getNamespace());
// Count the total number of entities
Pipeline p = Pipeline.create(options);
PCollection<Long> count = p.apply(read).apply(Count.globally());
PAssert.thatSingleton(count).isEqualTo(numEntities);
p.run();
}
use of org.hypertrace.entity.data.service.v1.Query in project beam by apache.
the class V1TestUtil method deleteAllEntities.
/**
* Delete all entities with the given ancestor.
*/
static void deleteAllEntities(V1TestOptions options, String project, String ancestor) throws Exception {
Datastore datastore = getDatastore(options, project);
Query query = V1TestUtil.makeAncestorKindQuery(options.getKind(), options.getNamespace(), ancestor);
V1TestReader reader = new V1TestReader(datastore, query, options.getNamespace());
V1TestWriter writer = new V1TestWriter(datastore, new DeleteMutationBuilder());
long numEntities = 0;
while (reader.advance()) {
Entity entity = reader.getCurrent();
numEntities++;
writer.write(entity);
}
writer.close();
LOG.info("Successfully deleted {} entities", numEntities);
}
Aggregations