use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method printRyaStreamsDetails_notConfigured.
@Test
public void printRyaStreamsDetails_notConfigured() throws Exception {
// Mock the object that performs the configure operation.
final RyaClient mockCommands = mock(RyaClient.class);
final GetInstanceDetails getDetails = mock(GetInstanceDetails.class);
when(mockCommands.getGetInstanceDetails()).thenReturn(getDetails);
// When getting the instance details, ensure they do not have RyaStreamsDetails to print.
final RyaDetails details = mock(RyaDetails.class);
when(details.getRyaStreamsDetails()).thenReturn(Optional.absent());
when(getDetails.getDetails(eq("unitTest"))).thenReturn(Optional.of(details));
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("unitTest");
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.printRyaStreamsDetails();
final String expected = "This instance of Rya has not been configured to use a Rya Streams subsystem.";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method configureRyaStreams.
@Test
public void configureRyaStreams() throws Exception {
// Mock the object that performs the configure operation.
final RyaClient mockCommands = mock(RyaClient.class);
final SetRyaStreamsConfiguration setStreams = mock(SetRyaStreamsConfiguration.class);
when(mockCommands.getSetRyaStreamsConfiguration()).thenReturn(setStreams);
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("unitTest");
// Verify that no Rya Streams Client is set to the state.
assertFalse(state.getShellState().getRyaStreamsCommands().isPresent());
try {
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.configureRyaStreams("localhost", 6);
// Verify the request was forwarded to the mocked interactor.
final RyaStreamsDetails expectedDetails = new RyaStreamsDetails("localhost", 6);
verify(setStreams).setRyaStreamsConfiguration(eq("unitTest"), eq(expectedDetails));
// Verify a RyaStreamsClient was created and added to the state.
assertTrue(state.getShellState().getRyaStreamsCommands().isPresent());
// Verify the correct message is reported.
final String expected = "The Rya Instance has been updated to use the provided Rya Streams subsystem. " + "Rya Streams commands are now avaiable while connected to this instance.";
assertEquals(expected, message);
} finally {
state.getShellState().getRyaStreamsCommands().get().close();
}
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaStreamsCommandsTest method printRyaStreamsDetails_noRyaDetails.
@Test
public void printRyaStreamsDetails_noRyaDetails() throws Exception {
// Mock the object that performs the configure operation.
final RyaClient mockCommands = mock(RyaClient.class);
final GetInstanceDetails getDetails = mock(GetInstanceDetails.class);
when(mockCommands.getGetInstanceDetails()).thenReturn(getDetails);
// When getting the instance details, ensure they are not found.
when(getDetails.getDetails(eq("unitTest"))).thenReturn(Optional.absent());
// Mock a shell state and connect it to a Rya instance.
final SharedShellState state = new SharedShellState();
state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockCommands);
state.connectedToInstance("unitTest");
// Execute the command.
final RyaStreamsCommands commands = new RyaStreamsCommands(state, mock(SparqlPrompt.class), mock(ConsolePrinter.class));
final String message = commands.printRyaStreamsDetails();
final String expected = "This instance does not have any Rya Details, so it is unable to be connected to the Rya Streams subsystem.";
assertEquals(expected, message);
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class RyaConnectionCommands method connectToInstance.
@CliCommand(value = CONNECT_INSTANCE_CMD, help = "Connect to a specific Rya instance")
public void connectToInstance(@CliOption(key = { "instance" }, mandatory = true, help = "The name of the Rya instance the shell will interact with.") final String ryaInstance) {
final RyaClient ryaClient = sharedState.getShellState().getConnectedCommands().get();
try {
final InstanceExists instanceExists = ryaClient.getInstanceExists();
// Make sure the requested instance exists.
if (!instanceExists.exists(ryaInstance)) {
throw new RuntimeException(String.format("'%s' does not match an existing Rya instance.", ryaInstance));
}
// Store the instance name in the shared state.
sharedState.connectedToInstance(ryaInstance);
// If the Rya instance is configured to interact with Rya Streams, then connect the
// Rya Streams client to the shared state.
final com.google.common.base.Optional<RyaDetails> ryaDetails = ryaClient.getGetInstanceDetails().getDetails(ryaInstance);
if (ryaDetails.isPresent()) {
final com.google.common.base.Optional<RyaStreamsDetails> streamsDetails = ryaDetails.get().getRyaStreamsDetails();
if (streamsDetails.isPresent()) {
final String kafkaHostname = streamsDetails.get().getHostname();
final int kafkaPort = streamsDetails.get().getPort();
final RyaStreamsClient streamsClient = KafkaRyaStreamsClientFactory.make(ryaInstance, kafkaHostname, kafkaPort);
sharedState.connectedToRyaStreams(streamsClient);
}
}
} catch (final RyaClientException e) {
throw new RuntimeException("Could not connect to Rya instance. Reason: " + e.getMessage(), e);
}
}
use of org.apache.rya.api.client.RyaClient in project incubator-rya by apache.
the class AccumuloBatchUpdatePCJIT method batchUpdate.
@Test
public void batchUpdate() throws Exception {
// Setup a Rya Client.
final AccumuloConnectionDetails connectionDetails = new AccumuloConnectionDetails(super.getUsername(), super.getPassword().toCharArray(), super.getInstanceName(), super.getZookeepers());
final RyaClient ryaClient = AccumuloRyaClientFactory.build(connectionDetails, super.getConnector());
// Install an instance of Rya on the mini accumulo cluster.
ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder().setEnablePcjIndex(true).build());
Sail sail = null;
try (final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(super.getConnector(), RYA_INSTANCE_NAME)) {
// Get a Sail connection backed by the installed Rya instance.
final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration();
ryaConf.setTablePrefix(RYA_INSTANCE_NAME);
ryaConf.set(ConfigUtils.CLOUDBASE_USER, super.getUsername());
ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, super.getPassword());
ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, super.getZookeepers());
ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, super.getInstanceName());
ryaConf.set(ConfigUtils.USE_PCJ, "true");
ryaConf.set(ConfigUtils.PCJ_STORAGE_TYPE, PrecomputedJoinStorageType.ACCUMULO.toString());
ryaConf.set(ConfigUtils.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.NO_UPDATE.toString());
sail = RyaSailFactory.getInstance(ryaConf);
// Load some statements into the Rya instance.
final ValueFactory vf = sail.getValueFactory();
final SailConnection sailConn = sail.getConnection();
sailConn.begin();
sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:likes"), vf.createURI("urn:icecream"));
sailConn.addStatement(vf.createURI("urn:Alice"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Bob"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:David"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Eve"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:Frank"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:blue"));
sailConn.addStatement(vf.createURI("urn:George"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:green"));
sailConn.addStatement(vf.createURI("urn:Hillary"), vf.createURI("urn:hasEyeColor"), vf.createURI("urn:brown"));
sailConn.commit();
sailConn.close();
// Create a PCJ for a SPARQL query.
final String sparql = "SELECT ?name WHERE { ?name <urn:likes> <urn:icecream> . ?name <urn:hasEyeColor> <urn:blue> . }";
final String pcjId = pcjStorage.createPcj(sparql);
// Run the test.
ryaClient.getBatchUpdatePCJ().batchUpdate(RYA_INSTANCE_NAME, pcjId);
// Verify the correct results were loaded into the PCJ table.
final Set<BindingSet> expectedResults = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Alice"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Bob"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Charlie"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:David"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Eve"));
expectedResults.add(bs);
bs = new MapBindingSet();
bs.addBinding("name", vf.createURI("urn:Frank"));
expectedResults.add(bs);
final Set<BindingSet> results = new HashSet<>();
try (CloseableIterator<BindingSet> resultsIt = pcjStorage.listResults(pcjId)) {
while (resultsIt.hasNext()) {
results.add(resultsIt.next());
}
}
assertEquals(expectedResults, results);
} finally {
if (sail != null) {
sail.shutDown();
}
}
}
Aggregations