Search in sources :

Example 1 with CreatePCJ

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);
}
Also used : ExportStrategy(org.apache.rya.api.client.CreatePCJ.ExportStrategy) AccumuloConnectionDetails(org.apache.rya.api.client.accumulo.AccumuloConnectionDetails) SparqlPrompt(org.apache.rya.shell.util.SparqlPrompt) CreatePCJ(org.apache.rya.api.client.CreatePCJ) RyaClient(org.apache.rya.api.client.RyaClient) InstallPrompt(org.apache.rya.shell.util.InstallPrompt) UninstallPrompt(org.apache.rya.shell.util.UninstallPrompt) Test(org.junit.Test)

Example 2 with CreatePCJ

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());
    }
}
Also used : MapBindingSet(org.openrdf.query.impl.MapBindingSet) BindingSet(org.openrdf.query.BindingSet) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) CreatePCJ(org.apache.rya.api.client.CreatePCJ) ValueFactory(org.openrdf.model.ValueFactory) ListQueryIds(org.apache.rya.indexing.pcj.fluo.api.ListQueryIds) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) MapBindingSet(org.openrdf.query.impl.MapBindingSet) DeletePCJ(org.apache.rya.api.client.DeletePCJ) Test(org.junit.Test)

Example 3 with CreatePCJ

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());
    }
}
Also used : AccumuloRyaDAO(org.apache.rya.accumulo.AccumuloRyaDAO) ListQueryIds(org.apache.rya.indexing.pcj.fluo.api.ListQueryIds) AccumuloPcjStorage(org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage) PrecomputedJoinStorage(org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage) CreatePCJ(org.apache.rya.api.client.CreatePCJ) ValueFactory(org.openrdf.model.ValueFactory) Test(org.junit.Test)

Example 4 with CreatePCJ

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);
}
Also used : CreatePCJ(org.apache.rya.api.client.CreatePCJ) AccumuloCreatePCJ(org.apache.rya.api.client.accumulo.AccumuloCreatePCJ) RyaDetails(org.apache.rya.api.instance.RyaDetails) RyaClient(org.apache.rya.api.client.RyaClient) DeletePCJ(org.apache.rya.api.client.DeletePCJ) Install(org.apache.rya.api.client.Install) InstallConfiguration(org.apache.rya.api.client.Install.InstallConfiguration) PCJDetails(org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails) Test(org.junit.Test)

Example 5 with CreatePCJ

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 }");
}
Also used : CreatePCJ(org.apache.rya.api.client.CreatePCJ) Test(org.junit.Test)

Aggregations

CreatePCJ (org.apache.rya.api.client.CreatePCJ)9 Test (org.junit.Test)9 Install (org.apache.rya.api.client.Install)4 InstallConfiguration (org.apache.rya.api.client.Install.InstallConfiguration)4 RyaClient (org.apache.rya.api.client.RyaClient)4 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)4 AccumuloCreatePCJ (org.apache.rya.api.client.accumulo.AccumuloCreatePCJ)3 RyaDetails (org.apache.rya.api.instance.RyaDetails)3 PCJDetails (org.apache.rya.api.instance.RyaDetails.PCJIndexDetails.PCJDetails)3 ListQueryIds (org.apache.rya.indexing.pcj.fluo.api.ListQueryIds)3 AccumuloPcjStorage (org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage)3 ValueFactory (org.openrdf.model.ValueFactory)3 DeletePCJ (org.apache.rya.api.client.DeletePCJ)2 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)2 BindingSet (org.openrdf.query.BindingSet)2 MapBindingSet (org.openrdf.query.impl.MapBindingSet)2 AccumuloRyaDAO (org.apache.rya.accumulo.AccumuloRyaDAO)1 ExportStrategy (org.apache.rya.api.client.CreatePCJ.ExportStrategy)1 AccumuloConnectionDetails (org.apache.rya.api.client.accumulo.AccumuloConnectionDetails)1 MongoPcjStorage (org.apache.rya.indexing.pcj.storage.mongo.MongoPcjStorage)1