Repository: incubator-rya Updated Branches: refs/heads/master 62c07940a -> c40dbbcfd
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e77e839d/extras/rya.benchmark/src/test/java/org/apache/rya/benchmark/query/QueryBenchmarkRunIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.benchmark/src/test/java/org/apache/rya/benchmark/query/QueryBenchmarkRunIT.java b/extras/rya.benchmark/src/test/java/org/apache/rya/benchmark/query/QueryBenchmarkRunIT.java new file mode 100644 index 0000000..e45002f --- /dev/null +++ b/extras/rya.benchmark/src/test/java/org/apache/rya/benchmark/query/QueryBenchmarkRunIT.java @@ -0,0 +1,196 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.rya.benchmark.query; + +import java.io.File; + +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.accumulo.minicluster.MiniAccumuloConfig; +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.apache.rya.benchmark.query.QueryBenchmark.QueryBenchmarkRun; +import org.apache.rya.benchmark.query.QueryBenchmark.QueryBenchmarkRun.NotEnoughResultsException; +import org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage; +import org.apache.rya.indexing.pcj.storage.accumulo.AccumuloPcjStorage; +import org.apache.zookeeper.ClientCnxn; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.openrdf.model.ValueFactory; +import org.openrdf.sail.Sail; +import org.openrdf.sail.SailConnection; +import org.openrdf.sail.SailException; + +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.api.client.Install.InstallConfiguration; +import mvm.rya.api.client.RyaClient; +import mvm.rya.api.client.accumulo.AccumuloConnectionDetails; +import mvm.rya.api.client.accumulo.AccumuloRyaClientFactory; +import mvm.rya.indexing.accumulo.ConfigUtils; +import mvm.rya.indexing.external.PrecomputedJoinIndexerConfig.PrecomputedJoinStorageType; +import mvm.rya.indexing.external.PrecomputedJoinIndexerConfig.PrecomputedJoinUpdaterType; +import mvm.rya.sail.config.RyaSailFactory; + +/** + * Integration tests {@link QueryBenchmarkRun}. + */ +public class QueryBenchmarkRunIT { + private static final Logger log = Logger.getLogger(QueryBenchmarkRunIT.class); + + private static final String RYA_INSTANCE_NAME = "test_"; + private static final String ACCUMULO_USER = "root"; + private static final String ACCUMULO_PASSWORD = "password"; + private static final String SPARQL_QUERY = "SELECT ?name WHERE { ?name <urn:likes> <urn:icecream> . ?name <urn:hasEyeColor> <urn:blue> . }"; + + private static MiniAccumuloCluster cluster = null; + private static Sail sail = null; + + @BeforeClass + public static void setup() throws Exception { + // Squash loud logs. + Logger.getLogger(ClientCnxn.class).setLevel(Level.ERROR); + + // Setup the Mini Accumulo Cluster. + final File miniDataDir = com.google.common.io.Files.createTempDir(); + final MiniAccumuloConfig cfg = new MiniAccumuloConfig( miniDataDir, ACCUMULO_PASSWORD); + cluster = new MiniAccumuloCluster(cfg); + cluster.start(); + + // Create a Rya Client connected to the Mini Accumulo Cluster. + final AccumuloConnectionDetails connDetails = new AccumuloConnectionDetails( + ACCUMULO_USER, + ACCUMULO_PASSWORD.toCharArray(), + cluster.getInstanceName(), + cluster.getZooKeepers()); + final Connector connector = cluster.getConnector(ACCUMULO_USER, ACCUMULO_PASSWORD); + final RyaClient ryaClient = AccumuloRyaClientFactory.build(connDetails, connector); + + // Install an instance of Rya on the mini cluster. + installRya(ryaClient); + + // Get a Sail object that is backed by the Rya store that is on the mini cluster. + final AccumuloRdfConfiguration ryaConf = new AccumuloRdfConfiguration(); + ryaConf.setTablePrefix(RYA_INSTANCE_NAME); + ryaConf.set(ConfigUtils.CLOUDBASE_USER, ACCUMULO_USER); + ryaConf.set(ConfigUtils.CLOUDBASE_PASSWORD, ACCUMULO_PASSWORD); + ryaConf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, cluster.getZooKeepers()); + ryaConf.set(ConfigUtils.CLOUDBASE_INSTANCE, cluster.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 data into the cluster that will match the query we're testing against. + loadTestStatements(); + + // Add a PCJ to the application that summarizes the query. + createTestPCJ(ryaClient); + } + + private static void installRya(final RyaClient ryaClient) throws Exception { + // Use the client to install the instance of Rya that will be used for the tests. + ryaClient.getInstall().install(RYA_INSTANCE_NAME, InstallConfiguration.builder() + .setEnableTableHashPrefix(false) + .setEnableGeoIndex(false) + .setEnableTemporalIndex(false) + .setEnableFreeTextIndex(false) + .setEnableEntityCentricIndex(false) + .setEnablePcjIndex(true) + .build()); + } + + private static void loadTestStatements() throws Exception { + 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(); + } + + private static void createTestPCJ(final RyaClient ryaClient) throws Exception { + // Create an empty PCJ within the Rya instance's PCJ storage for the test query. + final PrecomputedJoinStorage pcjs = new AccumuloPcjStorage(cluster.getConnector(ACCUMULO_USER, ACCUMULO_PASSWORD), RYA_INSTANCE_NAME); + final String pcjId = pcjs.createPcj(SPARQL_QUERY); + + + // Batch update the PCJ using the Rya Client. + ryaClient.getBatchUpdatePCJ().batchUpdate(RYA_INSTANCE_NAME, pcjId); + } + + @AfterClass + public static void teardown() { + if(sail != null) { + try { + log.info("Shutting down the Sail."); + sail.shutDown(); + } catch (final SailException e) { + log.error("Could not shut down the Sail.", e); + } + } + + if(cluster != null) { + try { + log.info("Shutting down the mini accumulo cluster."); + cluster.stop(); + } catch (final Exception e) { + log.error("Could not shut down the mini accumulo cluster.", e); + } + } + } + + @Test + public void read1() throws Exception { + new QueryBenchmarkRun(sail.getConnection(), SPARQL_QUERY, 1L).run(); + } + + @Test + public void read5() throws Exception { + new QueryBenchmarkRun(sail.getConnection(), SPARQL_QUERY, 5L).run(); + } + + @Test(expected = NotEnoughResultsException.class) + public void read10() throws Exception { + new QueryBenchmarkRun(sail.getConnection(), SPARQL_QUERY, 10L).run(); + } + + @Test + public void readAll() throws Exception { + new QueryBenchmarkRun(sail.getConnection(), SPARQL_QUERY).run(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e77e839d/extras/rya.console/pom.xml ---------------------------------------------------------------------- diff --git a/extras/rya.console/pom.xml b/extras/rya.console/pom.xml index c2332aa..df9e78a 100644 --- a/extras/rya.console/pom.xml +++ b/extras/rya.console/pom.xml @@ -143,6 +143,21 @@ <mainClass>org.springframework.shell.Bootstrap</mainClass> </transformer> </transformers> + + <!-- + Shading signed JARs will fail without this. + http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar + --> + <filters> + <filter> + <artifact>*:*</artifact> + <excludes> + <exclude>META-INF/*.SF</exclude> + <exclude>META-INF/*.DSA</exclude> + <exclude>META-INF/*.RSA</exclude> + </excludes> + </filter> + </filters> </configuration> </execution> </executions> @@ -185,4 +200,4 @@ </plugin> </plugins> </build> -</project> \ No newline at end of file +</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e77e839d/extras/rya.console/src/main/java/mvm/rya/shell/RyaAdminCommands.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/main/java/mvm/rya/shell/RyaAdminCommands.java b/extras/rya.console/src/main/java/mvm/rya/shell/RyaAdminCommands.java index bd91333..3c3e244 100644 --- a/extras/rya.console/src/main/java/mvm/rya/shell/RyaAdminCommands.java +++ b/extras/rya.console/src/main/java/mvm/rya/shell/RyaAdminCommands.java @@ -33,12 +33,13 @@ import org.springframework.stereotype.Component; import com.google.common.base.Optional; -import mvm.rya.api.client.RyaClientException; -import mvm.rya.api.client.RyaClient; import mvm.rya.api.client.GetInstanceDetails; -import mvm.rya.api.client.InstanceDoesNotExistException; import mvm.rya.api.client.Install.DuplicateInstanceNameException; import mvm.rya.api.client.Install.InstallConfiguration; +import mvm.rya.api.client.InstanceDoesNotExistException; +import mvm.rya.api.client.PCJDoesNotExistException; +import mvm.rya.api.client.RyaClient; +import mvm.rya.api.client.RyaClientException; import mvm.rya.api.instance.RyaDetails; import mvm.rya.shell.SharedShellState.ConnectionState; import mvm.rya.shell.SharedShellState.ShellState; @@ -55,6 +56,7 @@ public class RyaAdminCommands implements CommandMarker { public static final String CREATE_PCJ_CMD = "create-pcj"; public static final String DELETE_PCJ_CMD = "delete-pcj"; + public static final String BATCH_UPDATE_PCJ_CMD = "batch-update-pcj"; public static final String GET_INSTANCE_DETAILS_CMD = "get-instance-details"; public static final String INSTALL_CMD = "install"; public static final String LIST_INSTANCES_CMD = "list-instances"; @@ -69,7 +71,7 @@ public class RyaAdminCommands implements CommandMarker { * * @param state - Holds shared state between all of the command classes. (not null) * @param installPrompt - Prompts a user for installation details. (not null) - * @param sparqlPrompt - TODO doc + * @param sparqlPrompt - Prompts a user for create PCJ details. (not null) */ @Autowired public RyaAdminCommands(final SharedShellState state, final InstallPrompt installPrompt, final SparqlPrompt sparqlPrompt) { @@ -114,7 +116,8 @@ public class RyaAdminCommands implements CommandMarker { */ @CliAvailabilityIndicator({ CREATE_PCJ_CMD, - DELETE_PCJ_CMD }) + DELETE_PCJ_CMD, + BATCH_UPDATE_PCJ_CMD}) public boolean arePCJCommandsAvailable() { // The PCJ commands are only available if the Shell is connected to an instance of Rya // that is new enough to use the RyaDetailsRepository and is configured to maintain PCJs. @@ -138,18 +141,18 @@ public class RyaAdminCommands implements CommandMarker { public String listInstances() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient commands = shellState.getConnectedCommands().get(); - final Optional<String> ryaInstance = shellState.getRyaInstanceName(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final Optional<String> ryaInstanceName = shellState.getRyaInstanceName(); try { // Sort the names alphabetically. - final List<String> instanceNames = commands.getListInstances().listInstances(); + final List<String> instanceNames = ryaClient.getListInstances().listInstances(); Collections.sort( instanceNames ); final String report; final InstanceNamesFormatter formatter = new InstanceNamesFormatter(); - if(ryaInstance.isPresent()) { - report = formatter.format(instanceNames, ryaInstance.get()); + if(ryaInstanceName.isPresent()) { + report = formatter.format(instanceNames, ryaInstanceName.get()); } else { report = formatter.format(instanceNames); } @@ -163,7 +166,7 @@ public class RyaAdminCommands implements CommandMarker { @CliCommand(value = INSTALL_CMD, help = "Create a new instance of Rya.") public String install() { // Fetch the commands that are connected to the store. - final RyaClient commands = state.getShellState().getConnectedCommands().get(); + final RyaClient ryaClient = state.getShellState().getConnectedCommands().get(); String instanceName = null; InstallConfiguration installConfig = null; @@ -179,7 +182,7 @@ public class RyaAdminCommands implements CommandMarker { } // Execute the command. - commands.getInstall().install(instanceName, installConfig); + ryaClient.getInstall().install(instanceName, installConfig); return String.format("The Rya instance named '%s' has been installed.", instanceName); } catch(final DuplicateInstanceNameException e) { @@ -193,18 +196,18 @@ public class RyaAdminCommands implements CommandMarker { public String getInstanceDetails() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient commands = shellState.getConnectedCommands().get(); - final String ryaInstance = shellState.getRyaInstanceName().get(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final String ryaInstanceName = shellState.getRyaInstanceName().get(); try { - final Optional<RyaDetails> details = commands.getGetInstanceDetails().getDetails(ryaInstance); + final Optional<RyaDetails> details = ryaClient.getGetInstanceDetails().getDetails(ryaInstanceName); if(details.isPresent()) { return new RyaDetailsFormatter().format(details.get()); } else { return "This instance of Rya does not have a Rya Details table. Consider migrating to a newer version of Rya."; } } catch(final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); } catch (final RyaClientException e) { throw new RuntimeException("Could not get the instance details. Reason: " + e.getMessage(), e); } @@ -214,18 +217,18 @@ public class RyaAdminCommands implements CommandMarker { public String createPcj() { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient commands = shellState.getConnectedCommands().get(); - final String ryaInstance = shellState.getRyaInstanceName().get(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final String ryaInstanceName = shellState.getRyaInstanceName().get(); try { // Prompt the user for the SPARQL. final String sparql = sparqlPrompt.getSparql(); // Execute the command. - final String pcjId = commands.getCreatePCJ().createPCJ(ryaInstance, sparql); + final String pcjId = ryaClient.getCreatePCJ().createPCJ(ryaInstanceName, sparql); // Return a message that indicates the ID of the newly created ID. return String.format("The PCJ has been created. Its ID is '%s'.", pcjId); } catch (final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); } catch (final IOException | RyaClientException e) { throw new RuntimeException("Could not create the PCJ. Provided reasons: " + e.getMessage(), e); } @@ -237,18 +240,39 @@ public class RyaAdminCommands implements CommandMarker { final String pcjId) { // Fetch the command that is connected to the store. final ShellState shellState = state.getShellState(); - final RyaClient commands = shellState.getConnectedCommands().get(); - final String ryaInstance = shellState.getRyaInstanceName().get(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final String ryaInstanceName = shellState.getRyaInstanceName().get(); try { // Execute the command. - commands.getDeletePCJ().deletePCJ(ryaInstance, pcjId); + ryaClient.getDeletePCJ().deletePCJ(ryaInstanceName, pcjId); return "The PCJ has been deleted."; } catch (final InstanceDoesNotExistException e) { - throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstance), e); + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); } catch (final RyaClientException e) { throw new RuntimeException("The PCJ could not be deleted. Provided reason: " + e.getMessage(), e); } } + + @CliCommand(value = BATCH_UPDATE_PCJ_CMD, help = "Batch update a PCJ index using this client. This operation may take a long time.") + public String batchUpdatePcj( + @CliOption(key={"pcjId"}, mandatory = true, help = "The ID of the PCJ that will be updated.") + final String pcjId) { + // Fetch the command that is connected to the store. + final ShellState shellState = state.getShellState(); + final RyaClient ryaClient = shellState.getConnectedCommands().get(); + final String ryaInstanceName = shellState.getRyaInstanceName().get(); + + try { + ryaClient.getBatchUpdatePCJ().batchUpdate(ryaInstanceName, pcjId); + return "The PCJ's results have been updated."; + } catch(final InstanceDoesNotExistException e) { + throw new RuntimeException(String.format("A Rya instance named '%s' does not exist.", ryaInstanceName), e); + } catch(final PCJDoesNotExistException e) { + throw new RuntimeException(String.format("A PCJ with ID '%s' does not exist.", pcjId), e); + } catch(final RyaClientException e) { + throw new RuntimeException("The PCJ could not be deleted. Provided reason: " + e.getMessage(), e); + } + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e77e839d/extras/rya.console/src/main/java/mvm/rya/shell/util/InstallPrompt.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/main/java/mvm/rya/shell/util/InstallPrompt.java b/extras/rya.console/src/main/java/mvm/rya/shell/util/InstallPrompt.java index c4a81d2..44aa270 100644 --- a/extras/rya.console/src/main/java/mvm/rya/shell/util/InstallPrompt.java +++ b/extras/rya.console/src/main/java/mvm/rya/shell/util/InstallPrompt.java @@ -94,9 +94,13 @@ public interface InstallPrompt { builder.setEnablePcjIndex( enablePCJIndexing ); if(enablePCJIndexing) { - prompt = "PCJ Updater Fluo Application Name: "; - final String fluoAppName = promptString(prompt, Optional.<String>absent()); - builder.setFluoPcjAppName(fluoAppName); + final boolean useFluoApp = promptBoolean("Use a Fluo application to update the PCJ? ", Optional.absent()); + + if(useFluoApp) { + prompt = "PCJ Updater Fluo Application Name: "; + final String fluoAppName = promptString(prompt, Optional.<String>absent()); + builder.setFluoPcjAppName(fluoAppName); + } } prompt = makeFieldPrompt("Use Temporal Indexing", true); @@ -119,7 +123,11 @@ public interface InstallPrompt { reader.println(" Use Precomputed Join Indexing: " + installConfig.isPcjIndexEnabled()); if(installConfig.isPcjIndexEnabled()) { - reader.println(" PCJ Updater Fluo Application Name: " + installConfig.getFluoPcjAppName().get()); + if(installConfig.getFluoPcjAppName().isPresent()) { + reader.println(" PCJ Updater Fluo Application Name: " + installConfig.getFluoPcjAppName().get()); + } else { + reader.println(" Not using a PCJ Updater Fluo Application"); + } } reader.println(" Use Temporal Indexing: " + installConfig.isTemporalIndexEnabled()); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/e77e839d/extras/rya.console/src/test/java/mvm/rya/shell/RyaAdminCommandsTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.console/src/test/java/mvm/rya/shell/RyaAdminCommandsTest.java b/extras/rya.console/src/test/java/mvm/rya/shell/RyaAdminCommandsTest.java index f842a93..430e946 100644 --- a/extras/rya.console/src/test/java/mvm/rya/shell/RyaAdminCommandsTest.java +++ b/extras/rya.console/src/test/java/mvm/rya/shell/RyaAdminCommandsTest.java @@ -34,16 +34,18 @@ import org.junit.Test; import com.google.common.base.Optional; import com.google.common.collect.Lists; -import mvm.rya.api.client.RyaClientException; -import mvm.rya.api.client.RyaClient; +import mvm.rya.api.client.BatchUpdatePCJ; import mvm.rya.api.client.CreatePCJ; import mvm.rya.api.client.DeletePCJ; import mvm.rya.api.client.GetInstanceDetails; import mvm.rya.api.client.Install; -import mvm.rya.api.client.InstanceDoesNotExistException; -import mvm.rya.api.client.ListInstances; import mvm.rya.api.client.Install.DuplicateInstanceNameException; import mvm.rya.api.client.Install.InstallConfiguration; +import mvm.rya.api.client.InstanceDoesNotExistException; +import mvm.rya.api.client.ListInstances; +import mvm.rya.api.client.PCJDoesNotExistException; +import mvm.rya.api.client.RyaClient; +import mvm.rya.api.client.RyaClientException; import mvm.rya.api.client.accumulo.AccumuloConnectionDetails; import mvm.rya.api.instance.RyaDetails; import mvm.rya.api.instance.RyaDetails.EntityCentricIndexDetails; @@ -123,6 +125,33 @@ public class RyaAdminCommandsTest { } @Test + public void batchUpdatePCJ() throws InstanceDoesNotExistException, PCJDoesNotExistException, RyaClientException { + // Mock the object that performs the update PCJ operation. + final BatchUpdatePCJ mockBatchUpdatePCJ = mock(BatchUpdatePCJ.class); + + final RyaClient mockRyaClient = mock(RyaClient.class); + when(mockRyaClient.getBatchUpdatePCJ()).thenReturn( mockBatchUpdatePCJ ); + + final SharedShellState state = new SharedShellState(); + state.connectedToAccumulo(mock(AccumuloConnectionDetails.class), mockRyaClient); + final String instanceName = "unitTests"; + state.connectedToInstance(instanceName); + + // Execute the command. + final String pcjId = "12343214312"; + + final RyaAdminCommands commands = new RyaAdminCommands(state, mock(InstallPrompt.class), mock(SparqlPrompt.class)); + final String message = commands.batchUpdatePcj(pcjId); + + // Verify the values that were provided to the command were passed through to the BatchUpdatePCJ. + verify(mockBatchUpdatePCJ).batchUpdate(eq(instanceName), eq(pcjId)); + + // Verify a message is returned that explains what was updated. + final String expected = "The PCJ's results have been updated."; + assertEquals(message, expected); + } + + @Test public void getInstanceDetails() throws InstanceDoesNotExistException, RyaClientException { // This test is failed if the default timezone was not EST, so now it's fixed at EST. // If you get assert mismatch of EST!=EDT, try the deprecated getTimeZone("EST") instead.
