use of org.apache.rya.api.client.CreatePCJ in project incubator-rya by apache.
the class RyaAdminCommandsTest method createPCJ.
@Test
public void createPCJ() throws InstanceDoesNotExistException, RyaClientException, IOException {
// Mock the object that performs the create operation.
final String instanceName = "unitTest";
final String sparql = "SELECT * WHERE { ?person <http://isA> ?noun }";
final String pcjId = "123412342";
final CreatePCJ mockCreatePCJ = mock(CreatePCJ.class);
final Set<ExportStrategy> strategies = Sets.newHashSet(ExportStrategy.RYA);
when(mockCreatePCJ.createPCJ(eq(instanceName), eq(sparql), eq(strategies))).thenReturn(pcjId);
final RyaClient mockCommands = mock(RyaClient.class);
when(mockCommands.getCreatePCJ()).thenReturn(mockCreatePCJ);
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance(instanceName);
final SparqlPrompt mockSparqlPrompt = mock(SparqlPrompt.class);
when(mockSparqlPrompt.getSparql()).thenReturn(Optional.of(sparql));
// Execute the command.
final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mockSparqlPrompt, mock(UninstallPrompt.class));
final String message = commands.createPcj(true, false);
// Verify the values that were provided to the command were passed through to CreatePCJ.
verify(mockCreatePCJ).createPCJ(eq(instanceName), eq(sparql), eq(strategies));
// Verify a message is returned that explains what was created.
final String expected = "The PCJ has been created. Its ID is '123412342'.";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.CreatePCJ in project incubator-rya by apache.
the class AccumuloDeletePCJIT method deletePCJ.
@Test
public void deletePCJ() throws InstanceDoesNotExistException, RyaClientException, PCJStorageException, RepositoryException {
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
// Create a PCJ.
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId = createPCJ.createPCJ(getRyaInstanceName(), sparql);
// Verify a Query ID was added for the query within the Fluo app.
List<String> fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
assertEquals(1, fluoQueryIds.size());
// Insert some statements into Rya.
final ValueFactory vf = ryaRepo.getValueFactory();
ryaConn.add(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
// Verify the correct results were exported.
fluo.waitForObservers();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
final MapBindingSet bob = new MapBindingSet();
bob.addBinding("x", vf.createURI("http://Bob"));
final MapBindingSet charlie = new MapBindingSet();
charlie.addBinding("x", vf.createURI("http://Charlie"));
final Set<BindingSet> expected = Sets.<BindingSet>newHashSet(bob, charlie);
assertEquals(expected, results);
// Delete the PCJ.
final DeletePCJ deletePCJ = new AccumuloDeletePCJ(createConnectionDetails(), accumuloConn);
deletePCJ.deletePCJ(getRyaInstanceName(), pcjId);
// Ensure the PCJ's metadata has been removed from the storage.
assertTrue(pcjStorage.listPcjs().isEmpty());
// Ensure the PCJ has been removed from the Fluo application.
fluo.waitForObservers();
// Verify a Query ID was added for the query within the Fluo app.
fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
assertEquals(0, fluoQueryIds.size());
}
}
use of org.apache.rya.api.client.CreatePCJ in project incubator-rya by apache.
the class AccumuloDeletePCJIT method dropAndDestroyPCJ.
@Test
public void dropAndDestroyPCJ() throws InstanceDoesNotExistException, RyaClientException, PCJStorageException, RepositoryException, AccumuloException, AccumuloSecurityException, RyaDAOException {
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
// Create a PCJ.
final String sparql1 = "SELECT ?x " + "WHERE { " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId1 = createPCJ.createPCJ(getRyaInstanceName(), sparql1);
// Create a PCJ.
final String sparql2 = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "}";
final String pcjId2 = createPCJ.createPCJ(getRyaInstanceName(), sparql2);
// Verify a Query ID was added for the query within the Fluo app.
List<String> fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
assertEquals(2, fluoQueryIds.size());
// Insert some statements into Rya.
final ValueFactory vf = ryaRepo.getValueFactory();
ryaConn.add(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin"));
ryaConn.add(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
ryaConn.add(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://TacoJoint"));
// Verify the correct results were exported.
fluo.waitForObservers();
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName())) {
assertEquals("the PCJ's metadata was added the storage.", 2, pcjStorage.listPcjs().size());
// Delete all PCJ's.
AccumuloRyaDAO dao = RyaSailFactory.getAccumuloDAOWithUpdatedConfig(conf);
dao.dropAndDestroy();
// Ensure the PCJ's metadata has been removed from the storage.
assertTrue("the PCJ's metadata has been removed from the storage.", pcjStorage.listPcjs().isEmpty());
// Ensure the PCJ has been removed from the Fluo application.
fluo.waitForObservers();
// Verify Query IDs were deleted for the query within the Fluo app.
// TODO this fails, shows expected 0, but was 2.
// fluoQueryIds = new ListQueryIds().listQueryIds(fluoClient);
// assertEquals("Verify Query IDs were deleted for the query within the Fluo app.", 0, fluoQueryIds.size());
}
}
use of org.apache.rya.api.client.CreatePCJ in project incubator-rya by apache.
the class MongoDeletePCJIT method deletePCJ.
@Test
public void deletePCJ() throws Exception {
final MongoConnectionDetails connectionDetails = getConnectionDetails();
final RyaClient ryaClient = MongoRyaClientFactory.build(connectionDetails, getMongoClient());
// Initialize the commands that will be used by this test.
final CreatePCJ createPCJ = ryaClient.getCreatePCJ();
final Install installRya = ryaClient.getInstall();
final InstallConfiguration installConf = InstallConfiguration.builder().setEnablePcjIndex(true).build();
installRya.install(conf.getRyaInstanceName(), installConf);
System.out.println(getMongoClient().getDatabase(conf.getRyaInstanceName()).getCollection("instance_details").find().first().toJson());
// Create a PCJ.
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://TacoJoint>." + "}";
final String pcjId = createPCJ.createPCJ(conf.getRyaInstanceName(), sparql);
final DeletePCJ deletePCJ = ryaClient.getDeletePCJ();
deletePCJ.deletePCJ(conf.getRyaInstanceName(), pcjId);
// Verify the RyaDetails were updated to include the new PCJ.
final Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(conf.getRyaInstanceName());
final ImmutableMap<String, PCJDetails> details = ryaDetails.get().getPCJIndexDetails().getPCJDetails();
final PCJDetails pcjDetails = details.get(pcjId);
assertNull(pcjDetails);
}
use of org.apache.rya.api.client.CreatePCJ in project incubator-rya by apache.
the class AccumuloCreatePCJIT method createPCJ_instanceDoesNotExist.
@Test(expected = InstanceDoesNotExistException.class)
public void createPCJ_instanceDoesNotExist() throws InstanceDoesNotExistException, RyaClientException {
// Create a PCJ for a Rya instance that doesn't exist.
final CreatePCJ createPCJ = new AccumuloCreatePCJ(createConnectionDetails(), accumuloConn);
createPCJ.createPCJ("invalidInstanceName", "SELECT * where { ?a ?b ?c }");
}
Aggregations