http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/TimeUtils.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/TimeUtils.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/TimeUtils.java index b8ac63b..db760e5 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/TimeUtils.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/TimeUtils.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge.util; import java.io.IOException; import java.net.HttpURLConnection; @@ -74,23 +72,23 @@ public final class TimeUtils { * @return the NTP server {@link Date} or {@code null}. * @throws IOException */ - public static Date getNtpServerDate(String timeServerHost) throws IOException { + public static Date getNtpServerDate(final String timeServerHost) throws IOException { try { TimeInfo timeInfo = null; - NTPUDPClient timeClient = new NTPUDPClient(); + final NTPUDPClient timeClient = new NTPUDPClient(); timeClient.setDefaultTimeout(NTP_SERVER_TIMEOUT_MS); - InetAddress inetAddress = InetAddress.getByName(timeServerHost); + final InetAddress inetAddress = InetAddress.getByName(timeServerHost); if (inetAddress != null) { timeInfo = timeClient.getTime(inetAddress); if (timeInfo != null) { // TODO: which time to use? - long serverTime = timeInfo.getMessage().getTransmitTimeStamp().getTime(); + final long serverTime = timeInfo.getMessage().getTransmitTimeStamp().getTime(); //long serverTime = timeInfo.getReturnTime(); - Date ntpDate = new Date(serverTime); + final Date ntpDate = new Date(serverTime); return ntpDate; } } - } catch (IOException e) { + } catch (final IOException e) { throw new IOException("Unable to get NTP server time.", e); } return null; @@ -104,11 +102,11 @@ public final class TimeUtils { * @throws IOException * @throws ParseException */ - public static Date getRemoteMachineDate(String urlString) throws IOException, ParseException { + public static Date getRemoteMachineDate(final String urlString) throws IOException, ParseException { Date remoteDate = null; HttpURLConnection conn = null; try { - URL url = new URL(urlString); + final URL url = new URL(urlString); // Set up the initial connection conn = (HttpURLConnection)url.openConnection(); @@ -119,12 +117,12 @@ public final class TimeUtils { conn.connect(); - Map<String, List<String>> header = conn.getHeaderFields(); - for (String key : header.keySet()) { + final Map<String, List<String>> header = conn.getHeaderFields(); + for (final String key : header.keySet()) { if (key != null && HttpHeaders.DATE.equals(key)) { - List<String> data = header.get(key); - String dateString = data.get(0); - SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); + final List<String> data = header.get(key); + final String dateString = data.get(0); + final SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z"); remoteDate = sdf.parse(dateString); break; } @@ -147,16 +145,16 @@ public final class TimeUtils { * indicates that the machine's system time is ahead of the time server. A negative value indicates that * the machine's system time is behind of the time server. */ - public static Long getTimeDifference(Date ntpDate, Date machineDate, boolean isMachineLocal) { + public static Long getTimeDifference(final Date ntpDate, final Date machineDate, final boolean isMachineLocal) { Long diff = null; if (ntpDate != null && machineDate != null) { log.info("NTP Server Time: " + ntpDate); - String machineLabel = isMachineLocal ? "Local" : "Remote"; + final String machineLabel = isMachineLocal ? "Local" : "Remote"; log.info(machineLabel + " Machine Time: " + machineDate); diff = machineDate.getTime() - ntpDate.getTime(); - boolean isAhead = diff > 0; - String durationBreakdown = TimeUtils.getDurationBreakdown(diff, false); + final boolean isAhead = diff > 0; + final String durationBreakdown = TimeUtils.getDurationBreakdown(diff, false); log.info(machineLabel + " Machine time is " + (isAhead ? "ahead of" : "behind") + " NTP server time by " + durationBreakdown + "."); } @@ -171,13 +169,13 @@ public final class TimeUtils { * the local machine's system time is behind of the time server. * @throws IOException */ - public static Long getNtpServerAndLocalMachineTimeDifference(String timeServerHost) throws IOException { + public static Long getNtpServerAndLocalMachineTimeDifference(final String timeServerHost) throws IOException { log.info("Getting NTP Server time from " + timeServerHost + "..."); - Date ntpDate = getNtpServerDate(timeServerHost); + final Date ntpDate = getNtpServerDate(timeServerHost); Long diff = null; if (ntpDate != null) { log.info("Getting Local Machine time..."); - Date machineDate = new Date(); + final Date machineDate = new Date(); diff = getTimeDifference(ntpDate, machineDate, true); } @@ -195,13 +193,13 @@ public final class TimeUtils { * @throws ParseException * @throws IOException */ - public static Long getNtpServerAndRemoteMachineTimeDifference(String timeServerHost, String remoteMachineUrlString) throws IOException, ParseException { + public static Long getNtpServerAndRemoteMachineTimeDifference(final String timeServerHost, final String remoteMachineUrlString) throws IOException, ParseException { log.info("Getting NTP Server time from " + timeServerHost + "..."); - Date ntpDate = getNtpServerDate(timeServerHost); + final Date ntpDate = getNtpServerDate(timeServerHost); Long diff = null; if (ntpDate != null) { log.info("Getting Remote Machine time from " + remoteMachineUrlString + "..."); - Date machineDate = getRemoteMachineDate(remoteMachineUrlString); + final Date machineDate = getRemoteMachineDate(remoteMachineUrlString); diff = getTimeDifference(ntpDate, machineDate, false); } @@ -220,8 +218,8 @@ public final class TimeUtils { * @throws ParseException * @throws IOException */ - public static Long getNtpServerAndMachineTimeDifference(String timeServerHost, String machineUrlString) throws IOException, ParseException { - boolean isUrlLocalMachine = isUrlLocalMachine(machineUrlString); + public static Long getNtpServerAndMachineTimeDifference(final String timeServerHost, final String machineUrlString) throws IOException, ParseException { + final boolean isUrlLocalMachine = isUrlLocalMachine(machineUrlString); Long machineTimeOffset; if (isUrlLocalMachine) { @@ -240,8 +238,8 @@ public final class TimeUtils { * @throws IOException * @throws ParseException */ - public static Date getMachineDate(String urlString) throws IOException, ParseException { - boolean isMachineLocal = isUrlLocalMachine(urlString); + public static Date getMachineDate(final String urlString) throws IOException, ParseException { + final boolean isMachineLocal = isUrlLocalMachine(urlString); Date machineDate; if (isMachineLocal) { @@ -263,9 +261,9 @@ public final class TimeUtils { * @throws UnknownHostException * @throws MalformedURLException */ - public static boolean isUrlLocalMachine(String urlString) throws UnknownHostException, MalformedURLException { - String localAddress = InetAddress.getLocalHost().getHostAddress(); - String requestAddress = InetAddress.getByName(new URL(urlString).getHost()).getHostAddress(); + public static boolean isUrlLocalMachine(final String urlString) throws UnknownHostException, MalformedURLException { + final String localAddress = InetAddress.getLocalHost().getHostAddress(); + final String requestAddress = InetAddress.getByName(new URL(urlString).getHost()).getHostAddress(); return localAddress != null && requestAddress != null && localAddress.equals(requestAddress); } @@ -285,20 +283,20 @@ public final class TimeUtils { * to not display the sign. * @return A string of the form "X Days Y Hours Z Minutes A Seconds B Milliseconds". */ - public static String getDurationBreakdown(final long durationMs, boolean showSign) { + public static String getDurationBreakdown(final long durationMs, final boolean showSign) { long tempDurationMs = Math.abs(durationMs); - long days = TimeUnit.MILLISECONDS.toDays(tempDurationMs); + final long days = TimeUnit.MILLISECONDS.toDays(tempDurationMs); tempDurationMs -= TimeUnit.DAYS.toMillis(days); - long hours = TimeUnit.MILLISECONDS.toHours(tempDurationMs); + final long hours = TimeUnit.MILLISECONDS.toHours(tempDurationMs); tempDurationMs -= TimeUnit.HOURS.toMillis(hours); - long minutes = TimeUnit.MILLISECONDS.toMinutes(tempDurationMs); + final long minutes = TimeUnit.MILLISECONDS.toMinutes(tempDurationMs); tempDurationMs -= TimeUnit.MINUTES.toMillis(minutes); - long seconds = TimeUnit.MILLISECONDS.toSeconds(tempDurationMs); + final long seconds = TimeUnit.MILLISECONDS.toSeconds(tempDurationMs); tempDurationMs -= TimeUnit.SECONDS.toMillis(seconds); - long milliseconds = TimeUnit.MILLISECONDS.toMillis(tempDurationMs); + final long milliseconds = TimeUnit.MILLISECONDS.toMillis(tempDurationMs); - StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(); if (tempDurationMs != 0 && showSign) { sb.append(tempDurationMs > 0 ? "+" : "-"); } @@ -333,7 +331,7 @@ public final class TimeUtils { * @param date2 the second {@link Date}. * @return {@code true} if {@code date1} is before or equal to {@code date2}. {@code false} otherwise. */ - public static boolean dateBeforeInclusive(Date date1, Date date2) { + public static boolean dateBeforeInclusive(final Date date1, final Date date2) { return !date1.after(date2); } @@ -343,7 +341,7 @@ public final class TimeUtils { * @param date2 the second {@link Date}. * @return {@code true} if {@code date1} is after or equal to {@code date2}. {@code false} otherwise. */ - public static boolean dateAfterInclusive(Date date1, Date date2) { + public static boolean dateAfterInclusive(final Date date1, final Date date2) { return !date1.before(date2); } }
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/ToolConfigUtils.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/ToolConfigUtils.java b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/ToolConfigUtils.java index cc16bf7..6cfe315 100644 --- a/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/ToolConfigUtils.java +++ b/extras/rya.merger/src/main/java/org/apache/rya/accumulo/mr/merge/util/ToolConfigUtils.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.util; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge.util; import java.io.File; import java.io.IOException; @@ -59,14 +57,14 @@ public final class ToolConfigUtils { * @return a {@link Set} of argument strings. * @throws IOException */ - public static Set<String> getUserArguments(Configuration conf, String[] args) throws IOException { + public static Set<String> getUserArguments(final Configuration conf, final String[] args) throws IOException { String[] filteredArgs = new String[] {}; if (Arrays.asList(args).contains("-conf")) { // parse args new GenericOptionsParser(conf, args); - List<String> commandLineArgs = new ArrayList<>(); - for (String arg : args) { + final List<String> commandLineArgs = new ArrayList<>(); + for (final String arg : args) { if (arg.startsWith("-D")) { commandLineArgs.add(arg); } @@ -80,13 +78,13 @@ public final class ToolConfigUtils { // No real easy way of getting the name. // So, pulling it off the list of resource names in the Configuration's toString() method // where it should be the last one. - String confString = conf.toString(); - String resourceString = StringUtils.removeStart(confString, "Configuration: "); - List<String> resourceNames = Arrays.asList(StringUtils.split(resourceString, ", ")); - String configFilename = resourceNames.get(resourceNames.size() - 1); + final String confString = conf.toString(); + final String resourceString = StringUtils.removeStart(confString, "Configuration: "); + final List<String> resourceNames = Arrays.asList(StringUtils.split(resourceString, ", ")); + final String configFilename = resourceNames.get(resourceNames.size() - 1); - Set<String> toolArgsSet = new HashSet<>(); - File file = new File(configFilename); + final Set<String> toolArgsSet = new HashSet<>(); + final File file = new File(configFilename); // Check that the last resource name is the actual user's config by seeing if it's a file // on the system, the other resources seem to be contained in jars and so should fail here which // should happen if no config is supplied. @@ -95,7 +93,7 @@ public final class ToolConfigUtils { try { configuration = new XMLConfiguration(configFilename); toolArgsSet.addAll(getConfigArguments(configuration)); - } catch (ConfigurationException e) { + } catch (final ConfigurationException e) { log.error("Unable to load configuration file.", e); } } @@ -110,13 +108,13 @@ public final class ToolConfigUtils { * @param configuration the {@link XMLConfiguration}. * @return the set of argument strings. */ - public static Set<String> getConfigArguments(XMLConfiguration configuration) { - int size = configuration.getList("property.name").size(); - TreeSet<String> configArgs = new TreeSet<>(); + public static Set<String> getConfigArguments(final XMLConfiguration configuration) { + final int size = configuration.getList("property.name").size(); + final TreeSet<String> configArgs = new TreeSet<>(); for (int i = 0; i < size; i++) { - String propertyName = configuration.getString("property(" + i + ").name"); - String propertyValue = configuration.getString("property(" + i + ").value"); - String argument = makeArgument(propertyName, propertyValue); + final String propertyName = configuration.getString("property(" + i + ").name"); + final String propertyValue = configuration.getString("property(" + i + ").value"); + final String argument = makeArgument(propertyName, propertyValue); configArgs.add(argument); } return configArgs; @@ -130,7 +128,7 @@ public final class ToolConfigUtils { * @param value the value. * @return the argument string. */ - public static String makeArgument(String propertyName, String value) { + public static String makeArgument(final String propertyName, final String value) { return "-D" + propertyName + "=" + value; } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java index c4ec2ae..c4dae61 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/CopyToolTest.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; @@ -137,11 +135,11 @@ public class CopyToolTest { accumuloDualInstanceDriver.tearDown(); } - private void assertStatementInChild(String description, int verifyResultCount, RyaStatement matchStatement) throws RyaDAOException { + private void assertStatementInChild(final String description, final int verifyResultCount, final RyaStatement matchStatement) throws RyaDAOException { TestUtils.assertStatementInInstance(description, verifyResultCount, matchStatement, childDao, childConfig); } - private void copyToolRun(Date startDate) throws AccumuloException, AccumuloSecurityException { + private void copyToolRun(final Date startDate) throws AccumuloException, AccumuloSecurityException { copyTool = new CopyTool(); copyTool.setupAndRun(new String[] { makeArgument(MRUtils.AC_MOCK_PROP, Boolean.toString(IS_MOCK)), @@ -172,8 +170,8 @@ public class CopyToolTest { makeArgument(MergeTool.START_TIME_PROP, MergeTool.getStartTimeString(startDate, IS_START_TIME_DIALOG_ENABLED)) }); - Configuration toolConfig = copyTool.getConf(); - String zooKeepers = toolConfig.get(MRUtils.AC_ZK_PROP + CHILD_SUFFIX); + final Configuration toolConfig = copyTool.getConf(); + final String zooKeepers = toolConfig.get(MRUtils.AC_ZK_PROP + CHILD_SUFFIX); MergeTool.setDuplicateKeysForProperty(childConfig, MRUtils.AC_ZK_PROP, zooKeepers); log.info("Finished running tool."); @@ -181,20 +179,20 @@ public class CopyToolTest { @Test public void testCopyTool() throws Exception { - RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("coach", "called", "timeout", LAST_MONTH); + final RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("coach", "called", "timeout", LAST_MONTH); - RyaStatement ryaStatementShouldCopy1 = createRyaStatement("bob", "catches", "ball", YESTERDAY); - RyaStatement ryaStatementShouldCopy2 = createRyaStatement("bill", "talks to", "john", YESTERDAY); - RyaStatement ryaStatementShouldCopy3 = createRyaStatement("susan", "eats", "burgers", TODAY); - RyaStatement ryaStatementShouldCopy4 = createRyaStatement("ronnie", "plays", "guitar", TODAY); + final RyaStatement ryaStatementShouldCopy1 = createRyaStatement("bob", "catches", "ball", YESTERDAY); + final RyaStatement ryaStatementShouldCopy2 = createRyaStatement("bill", "talks to", "john", YESTERDAY); + final RyaStatement ryaStatementShouldCopy3 = createRyaStatement("susan", "eats", "burgers", TODAY); + final RyaStatement ryaStatementShouldCopy4 = createRyaStatement("ronnie", "plays", "guitar", TODAY); - RyaStatement ryaStatementDoesNotExist1 = createRyaStatement("nobody", "was", "here", LAST_MONTH); - RyaStatement ryaStatementDoesNotExist2 = createRyaStatement("statement", "not", "found", YESTERDAY); - RyaStatement ryaStatementDoesNotExist3 = createRyaStatement("key", "does not", "exist", TODAY); + final RyaStatement ryaStatementDoesNotExist1 = createRyaStatement("nobody", "was", "here", LAST_MONTH); + final RyaStatement ryaStatementDoesNotExist2 = createRyaStatement("statement", "not", "found", YESTERDAY); + final RyaStatement ryaStatementDoesNotExist3 = createRyaStatement("key", "does not", "exist", TODAY); // This statement was modified by the child to change the column visibility. // The parent should combine the child's visibility with its visibility. - RyaStatement ryaStatementVisibilityDifferent = createRyaStatement("I", "see", "you", YESTERDAY); + final RyaStatement ryaStatementVisibilityDifferent = createRyaStatement("I", "see", "you", YESTERDAY); ryaStatementVisibilityDifferent.setColumnVisibility(PARENT_COLUMN_VISIBILITY.getExpression()); // Setup initial parent instance with 7 rows @@ -217,8 +215,8 @@ public class CopyToolTest { // Copy Tool made child instance so hook the tables and dao into the driver. - String childUser = accumuloDualInstanceDriver.getChildUser(); - Connector childConnector = ConfigUtils.getConnector(childConfig); + final String childUser = accumuloDualInstanceDriver.getChildUser(); + final Connector childConnector = ConfigUtils.getConnector(childConfig); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setConnector(childConnector); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpTables(); @@ -228,21 +226,21 @@ public class CopyToolTest { // Update child config to include changes made from copy process - SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); + final SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH); childSecOps.changeUserAuthorizations(childUser, newChildAuths); - String childAuthString = newChildAuths.toString(); - List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); + final String childAuthString = newChildAuths.toString(); + final List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); childConfig.set(MRUtils.AC_AUTH_PROP, childAuthString); - for (String key : duplicateKeys) { + for (final String key : duplicateKeys) { childConfig.set(key, childAuthString); } AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX, childConfig); AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX, childConfig); AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Iterator<Entry<Key, Value>> iterator = scanner.iterator(); + final Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); + final Iterator<Entry<Key, Value>> iterator = scanner.iterator(); int count = 0; while (iterator.hasNext()) { iterator.next(); @@ -273,21 +271,21 @@ public class CopyToolTest { // Check that it can be queried with parent's visibility childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, PARENT_AUTH); - SecurityOperations secOps = IS_MOCK ? accumuloDualInstanceDriver.getChildSecOps() : childSecOps; + final SecurityOperations secOps = IS_MOCK ? accumuloDualInstanceDriver.getChildSecOps() : childSecOps; newChildAuths = AccumuloRyaUtils.addUserAuths(accumuloDualInstanceDriver.getChildUser(), secOps, PARENT_AUTH); secOps.changeUserAuthorizations(accumuloDualInstanceDriver.getChildUser(), newChildAuths); assertStatementInChild("Child missing statement with parent visibility", 1, ryaStatementVisibilityDifferent); // Check that it can NOT be queried with some other visibility childConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "bad_auth"); - CloseableIteration<RyaStatement, RyaDAOException> iter = childDao.getQueryEngine().query(ryaStatementVisibilityDifferent, childConfig); + final CloseableIteration<RyaStatement, RyaDAOException> iter = childDao.getQueryEngine().query(ryaStatementVisibilityDifferent, childConfig); count = 0; try { while (iter.hasNext()) { iter.next(); count++; } - } catch (Exception e) { + } catch (final Exception e) { // Expected if (!(e.getCause() instanceof AccumuloSecurityException)) { fail(); @@ -316,8 +314,8 @@ public class CopyToolTest { // Import Directory Tool made child instance so hook the tables and dao into the driver. - String childUser = accumuloDualInstanceDriver.getChildUser(); - Connector childConnector = ConfigUtils.getConnector(childConfig); + final String childUser = accumuloDualInstanceDriver.getChildUser(); + final Connector childConnector = ConfigUtils.getConnector(childConfig); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setConnector(childConnector); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpTables(); @@ -326,13 +324,13 @@ public class CopyToolTest { // Update child config to include changes made from import directory process - SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); - Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH); + final SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); + final Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH); childSecOps.changeUserAuthorizations(childUser, newChildAuths); - String childAuthString = newChildAuths.toString(); - List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); + final String childAuthString = newChildAuths.toString(); + final List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); childConfig.set(MRUtils.AC_AUTH_PROP, childAuthString); - for (String key : duplicateKeys) { + for (final String key : duplicateKeys) { childConfig.set(key, childAuthString); } @@ -341,8 +339,8 @@ public class CopyToolTest { //AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX, childConfig); AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Iterator<Entry<Key, Value>> iterator = scanner.iterator(); + final Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); + final Iterator<Entry<Key, Value>> iterator = scanner.iterator(); int count = 0; while (iterator.hasNext()) { iterator.next(); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java index 1f077db..7c89466 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/MergeToolTest.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; @@ -135,11 +133,11 @@ public class MergeToolTest { accumuloDualInstanceDriver.tearDown(); } - private void assertStatementInParent(String description, int verifyResultCount, RyaStatement matchStatement) throws RyaDAOException { + private void assertStatementInParent(final String description, final int verifyResultCount, final RyaStatement matchStatement) throws RyaDAOException { TestUtils.assertStatementInInstance(description, verifyResultCount, matchStatement, parentDao, parentConfig); } - private void mergeToolRun(Date startDate) { + private void mergeToolRun(final Date startDate) { MergeTool.setupAndRun(new String[] { makeArgument(MRUtils.AC_MOCK_PROP, Boolean.toString(IS_MOCK)), makeArgument(MRUtils.AC_INSTANCE_PROP, PARENT_INSTANCE), @@ -169,37 +167,37 @@ public class MergeToolTest { public void testMergeTool() throws Exception { // This statement was in both parent/child instances a month ago and is before the start time of yesterday // but it was left alone. It should remain in the parent after merging. - RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("coach", "called", "timeout", LAST_MONTH); + final RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("coach", "called", "timeout", LAST_MONTH); // This statement was in both parent/child instances a month ago but after the start time of yesterday // the parent deleted it and the child still has it. It should stay deleted in the parent after merging. - RyaStatement ryaStatementParentDeletedAfter = createRyaStatement("parent", "deleted", "after", LAST_MONTH); + final RyaStatement ryaStatementParentDeletedAfter = createRyaStatement("parent", "deleted", "after", LAST_MONTH); // This statement was added by the parent after the start time of yesterday and doesn't exist in the child. // It should stay in the parent after merging. - RyaStatement ryaStatementParentAddedAfter = createRyaStatement("parent", "added", "after", TODAY); + final RyaStatement ryaStatementParentAddedAfter = createRyaStatement("parent", "added", "after", TODAY); // This statement was in both parent/child instances a month ago but after the start time of yesterday // the child deleted it and the parent still has it. It should be deleted from the parent after merging. - RyaStatement ryaStatementChildDeletedAfter = createRyaStatement("child", "deleted", "after", LAST_MONTH); + final RyaStatement ryaStatementChildDeletedAfter = createRyaStatement("child", "deleted", "after", LAST_MONTH); // This statement was added by the child after the start time of yesterday and doesn't exist in the parent. // It should be added to the parent after merging. - RyaStatement ryaStatementChildAddedAfter = createRyaStatement("child", "added", "after", TODAY); + final RyaStatement ryaStatementChildAddedAfter = createRyaStatement("child", "added", "after", TODAY); // This statement was modified by the child after the start of yesterday (The timestamp changes after updating) // It should be updated in the parent to match the child. - RyaStatement ryaStatementUpdatedByChild = createRyaStatement("bob", "catches", "ball", LAST_MONTH); + final RyaStatement ryaStatementUpdatedByChild = createRyaStatement("bob", "catches", "ball", LAST_MONTH); - RyaStatement ryaStatementUntouchedByChild = createRyaStatement("bill", "talks to", "john", LAST_MONTH); + final RyaStatement ryaStatementUntouchedByChild = createRyaStatement("bill", "talks to", "john", LAST_MONTH); - RyaStatement ryaStatementDeletedByChild = createRyaStatement("susan", "eats", "burgers", LAST_MONTH); + final RyaStatement ryaStatementDeletedByChild = createRyaStatement("susan", "eats", "burgers", LAST_MONTH); - RyaStatement ryaStatementAddedByChild = createRyaStatement("ronnie", "plays", "guitar", TODAY); + final RyaStatement ryaStatementAddedByChild = createRyaStatement("ronnie", "plays", "guitar", TODAY); // This statement was modified by the child to change the column visibility. // The parent should combine the child's visibility with its visibility. - RyaStatement ryaStatementVisibilityDifferent = createRyaStatement("I", "see", "you", LAST_MONTH); + final RyaStatement ryaStatementVisibilityDifferent = createRyaStatement("I", "see", "you", LAST_MONTH); ryaStatementVisibilityDifferent.setColumnVisibility(PARENT_COLUMN_VISIBILITY.getExpression()); // Setup initial parent instance with 7 rows @@ -235,12 +233,12 @@ public class MergeToolTest { mergeToolRun(YESTERDAY); - for (String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { + for (final String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + tableSuffix, parentConfig); } - Scanner scanner = AccumuloRyaUtils.getScanner(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); - Iterator<Entry<Key, Value>> iterator = scanner.iterator(); + final Scanner scanner = AccumuloRyaUtils.getScanner(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); + final Iterator<Entry<Key, Value>> iterator = scanner.iterator(); int count = 0; while (iterator.hasNext()) { iterator.next(); @@ -265,20 +263,20 @@ public class MergeToolTest { // Check that it can be queried with child's visibility parentConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, CHILD_AUTH); - Authorizations newParentAuths = AccumuloRyaUtils.addUserAuths(accumuloDualInstanceDriver.getParentUser(), accumuloDualInstanceDriver.getParentSecOps(), CHILD_AUTH); + final Authorizations newParentAuths = AccumuloRyaUtils.addUserAuths(accumuloDualInstanceDriver.getParentUser(), accumuloDualInstanceDriver.getParentSecOps(), CHILD_AUTH); accumuloDualInstanceDriver.getParentSecOps().changeUserAuthorizations(accumuloDualInstanceDriver.getParentUser(), newParentAuths); assertStatementInParent("Parent missing statement with child visibility", 1, ryaStatementVisibilityDifferent); // Check that it can NOT be queried with some other visibility parentConfig.set(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, "bad_auth"); - CloseableIteration<RyaStatement, RyaDAOException> iter = parentDao.getQueryEngine().query(ryaStatementVisibilityDifferent, parentConfig); + final CloseableIteration<RyaStatement, RyaDAOException> iter = parentDao.getQueryEngine().query(ryaStatementVisibilityDifferent, parentConfig); count = 0; try { while (iter.hasNext()) { iter.next(); count++; } - } catch (Exception e) { + } catch (final Exception e) { // Expected if (!(e.getCause() instanceof AccumuloSecurityException)) { fail(); @@ -302,14 +300,14 @@ public class MergeToolTest { log.info("DONE"); } - private static RyaStatement createRyaStatementUnique(String s, String p, String o, Date date) throws Exception { - String uniquePart = Long.toString(System.currentTimeMillis() & 0xffffff, 64); + private static RyaStatement createRyaStatementUnique(final String s, final String p, final String o, final Date date) throws Exception { + final String uniquePart = Long.toString(System.currentTimeMillis() & 0xffffff, 64); return createRyaStatement(s+uniquePart, p+uniquePart, o+uniquePart, date); } - private static RyaStatement createRyaStatementUniqueAdd(String s, String p, String o, Date date, AccumuloRyaDAO dao1, AccumuloRyaDAO dao2) throws Exception { - String uniquePart = Long.toString(System.currentTimeMillis() & 0xffffff, 64); - RyaStatement rs = createRyaStatement(s + uniquePart, p + uniquePart, o + uniquePart, date); + private static RyaStatement createRyaStatementUniqueAdd(final String s, final String p, final String o, final Date date, final AccumuloRyaDAO dao1, final AccumuloRyaDAO dao2) throws Exception { + final String uniquePart = Long.toString(System.currentTimeMillis() & 0xffffff, 64); + final RyaStatement rs = createRyaStatement(s + uniquePart, p + uniquePart, o + uniquePart, date); if (dao1 != null) { dao1.add(rs); } @@ -321,8 +319,8 @@ public class MergeToolTest { @Test public void testMissingParentNewChild() throws Exception { - RyaStatement stmtNewInChild = createRyaStatementUnique("s_newInChild", "p_newInChild", "o_newInChild", null); - RyaStatement stmtSameInBoth = createRyaStatementUnique("s_same", "p_same", "o_same", LAST_MONTH); + final RyaStatement stmtNewInChild = createRyaStatementUnique("s_newInChild", "p_newInChild", "o_newInChild", null); + final RyaStatement stmtSameInBoth = createRyaStatementUnique("s_same", "p_same", "o_same", LAST_MONTH); childDao.add(stmtNewInChild); // Merging should add statement to parent childDao.add(stmtSameInBoth); // Merging should ignore statement parentDao.add(stmtSameInBoth); // Merging should ignore statement @@ -333,14 +331,14 @@ public class MergeToolTest { @Test public void testOldParentMissingChild() throws Exception { - RyaStatement stmtMissingInChildOld = createRyaStatementUniqueAdd("s_notInChild", "p_notInChild", "o_notInChild", LAST_MONTH, parentDao, null); + final RyaStatement stmtMissingInChildOld = createRyaStatementUniqueAdd("s_notInChild", "p_notInChild", "o_notInChild", LAST_MONTH, parentDao, null); mergeToolRun(YESTERDAY); assertStatementInParent("Missing in child statement deleted old in parent ", 0, stmtMissingInChildOld); } @Test public void testNewParentEmptyChild() throws Exception { - RyaStatement stmtNewP_MisC = createRyaStatementUniqueAdd("s_NewP_MisC", "p_NewP_MisC", "o_NewP_MisC", null, parentDao, null); + final RyaStatement stmtNewP_MisC = createRyaStatementUniqueAdd("s_NewP_MisC", "p_NewP_MisC", "o_NewP_MisC", null, parentDao, null); AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); AccumuloRyaUtils.printTable(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); mergeToolRun(YESTERDAY); @@ -350,8 +348,8 @@ public class MergeToolTest { @Test public void testNewParentMissingChild() throws Exception { - RyaStatement stmtNewP_MisC = createRyaStatementUniqueAdd("s_NewP_MisC", "p_NewP_MisC", "o_NewP_MisC", null, parentDao, null); - RyaStatement stmtOldP_OldC = createRyaStatementUniqueAdd("s_OldP_OldC", "p_OldP_OldC", "o_OldP_OldC", LAST_MONTH, parentDao, childDao); + final RyaStatement stmtNewP_MisC = createRyaStatementUniqueAdd("s_NewP_MisC", "p_NewP_MisC", "o_NewP_MisC", null, parentDao, null); + final RyaStatement stmtOldP_OldC = createRyaStatementUniqueAdd("s_OldP_OldC", "p_OldP_OldC", "o_OldP_OldC", LAST_MONTH, parentDao, childDao); AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); AccumuloRyaUtils.printTable(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); @@ -362,7 +360,7 @@ public class MergeToolTest { @Test public void testEmptyParentNewChild() throws Exception { - RyaStatement stmtMisP_NewC_addP_z = createRyaStatementUniqueAdd("zs_MisP_NewC", "zp_MisP_NewC", "zo_MisP_NewC", null , null , childDao); + final RyaStatement stmtMisP_NewC_addP_z = createRyaStatementUniqueAdd("zs_MisP_NewC", "zp_MisP_NewC", "zo_MisP_NewC", null , null , childDao); AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); AccumuloRyaUtils.printTable(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); @@ -388,11 +386,11 @@ public class MergeToolTest { @Test public void testWithParentSplits() throws Exception { // set splits, 4 tablets created: <b b*-g g*-v >v - TreeSet<Text> splits = new TreeSet<Text>(); + final TreeSet<Text> splits = new TreeSet<Text>(); splits.add(new Text("b")); splits.add(new Text("g")); splits.add(new Text("v")); - for (String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { + for (final String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { parentConnector.tableOperations().addSplits(PARENT_TABLE_PREFIX + tableSuffix, splits); } addAndVerifySplitableStatements(); @@ -401,11 +399,11 @@ public class MergeToolTest { @Test public void testWithChildSplits() throws Exception { // set splits, 4 tablets created: <b b*-g g*-v >v - TreeSet<Text> splits = new TreeSet<Text>(); + final TreeSet<Text> splits = new TreeSet<Text>(); splits.add(new Text("b")); splits.add(new Text("g")); splits.add(new Text("v")); - for (String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { + for (final String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { childConnector.tableOperations().addSplits(CHILD_TABLE_PREFIX + tableSuffix, splits); } addAndVerifySplitableStatements(); @@ -414,14 +412,14 @@ public class MergeToolTest { @Test public void testWithParentAndChildSplits() throws Exception { // set splits, 4 tablets created: <b b*-g g*-v >v - TreeSet<Text> splits = new TreeSet<Text>(); + final TreeSet<Text> splits = new TreeSet<Text>(); splits.add(new Text("b")); splits.add(new Text("g")); splits.add(new Text("v")); - for (String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { + for (final String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { parentConnector.tableOperations().addSplits(PARENT_TABLE_PREFIX + tableSuffix, splits); } - for (String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { + for (final String tableSuffix : AccumuloInstanceDriver.TABLE_NAME_SUFFIXES) { childConnector.tableOperations().addSplits(CHILD_TABLE_PREFIX + tableSuffix, splits); } addAndVerifySplitableStatements(); @@ -440,22 +438,22 @@ public class MergeToolTest { */ private void addAndVerifySplitableStatements() throws Exception { // Old=older, New=newer, Mis=missing, P=parent, C=child, delP=del from parent, addP=add to parent, Noth=do nothing - RyaStatement stmtOldP_MisC_delP_a = createRyaStatementUniqueAdd("as_OldP_MisC", "ap_OldP_MisC", "ao_OldP_MisC", LAST_MONTH, parentDao, null); - RyaStatement stmtOldP_MisC_delP_f = createRyaStatementUniqueAdd("fs_OldP_MisC", "fp_OldP_MisC", "fo_OldP_MisC", LAST_MONTH, parentDao, null); - RyaStatement stmtOldP_MisC_delP_u = createRyaStatementUniqueAdd("us_OldP_MisC", "up_OldP_MisC", "uo_OldP_MisC", LAST_MONTH, parentDao, null); - RyaStatement stmtOldP_MisC_delP_z = createRyaStatementUniqueAdd("zs_OldP_MisC", "zp_OldP_MisC", "zo_OldP_MisC", LAST_MONTH, parentDao, null); - RyaStatement stmtNewP_MisC_Noth_a = createRyaStatementUniqueAdd("as_NewP_MisC", "ap_NewP_MisC", "ao_NewP_MisC", null , parentDao, null); - RyaStatement stmtNewP_MisC_Noth_f = createRyaStatementUniqueAdd("fs_NewP_MisC", "fp_NewP_MisC", "fo_NewP_MisC", null , parentDao, null); - RyaStatement stmtNewP_MisC_Noth_u = createRyaStatementUniqueAdd("us_NewP_MisC", "up_NewP_MisC", "uo_NewP_MisC", null , parentDao, null); - RyaStatement stmtNewP_MisC_Noth_z = createRyaStatementUniqueAdd("zs_NewP_MisC", "zp_NewP_MisC", "zo_NewP_MisC", null , parentDao, null); - RyaStatement stmtMisP_OldC_Noth_a = createRyaStatementUniqueAdd("as_MisP_OldC", "ap_MisP_OldC", "ao_MisP_OldC", LAST_MONTH, null , childDao); - RyaStatement stmtMisP_OldC_Noth_f = createRyaStatementUniqueAdd("fs_MisP_OldC", "fp_MisP_OldC", "fo_MisP_OldC", LAST_MONTH, null , childDao); - RyaStatement stmtMisP_OldC_Noth_u = createRyaStatementUniqueAdd("us_MisP_OldC", "up_MisP_OldC", "uo_MisP_OldC", LAST_MONTH, null , childDao); - RyaStatement stmtMisP_OldC_addP_z = createRyaStatementUniqueAdd("zs_MisP_OldC", "zp_MisP_OldC", "zo_MisP_OldC", LAST_MONTH, null , childDao); - RyaStatement stmtMisP_NewC_addP_a = createRyaStatementUniqueAdd("as_MisP_NewC", "ap_MisP_NewC", "ao_MisP_NewC", null , null , childDao); - RyaStatement stmtMisP_NewC_addP_f = createRyaStatementUniqueAdd("fs_MisP_NewC", "fp_MisP_NewC", "fo_MisP_NewC", null , null , childDao); - RyaStatement stmtMisP_NewC_addP_u = createRyaStatementUniqueAdd("us_MisP_NewC", "up_MisP_NewC", "uo_MisP_NewC", null , null , childDao); - RyaStatement stmtMisP_NewC_addP_z = createRyaStatementUniqueAdd("zs_MisP_NewC", "zp_MisP_NewC", "zo_MisP_NewC", null , null , childDao); + final RyaStatement stmtOldP_MisC_delP_a = createRyaStatementUniqueAdd("as_OldP_MisC", "ap_OldP_MisC", "ao_OldP_MisC", LAST_MONTH, parentDao, null); + final RyaStatement stmtOldP_MisC_delP_f = createRyaStatementUniqueAdd("fs_OldP_MisC", "fp_OldP_MisC", "fo_OldP_MisC", LAST_MONTH, parentDao, null); + final RyaStatement stmtOldP_MisC_delP_u = createRyaStatementUniqueAdd("us_OldP_MisC", "up_OldP_MisC", "uo_OldP_MisC", LAST_MONTH, parentDao, null); + final RyaStatement stmtOldP_MisC_delP_z = createRyaStatementUniqueAdd("zs_OldP_MisC", "zp_OldP_MisC", "zo_OldP_MisC", LAST_MONTH, parentDao, null); + final RyaStatement stmtNewP_MisC_Noth_a = createRyaStatementUniqueAdd("as_NewP_MisC", "ap_NewP_MisC", "ao_NewP_MisC", null , parentDao, null); + final RyaStatement stmtNewP_MisC_Noth_f = createRyaStatementUniqueAdd("fs_NewP_MisC", "fp_NewP_MisC", "fo_NewP_MisC", null , parentDao, null); + final RyaStatement stmtNewP_MisC_Noth_u = createRyaStatementUniqueAdd("us_NewP_MisC", "up_NewP_MisC", "uo_NewP_MisC", null , parentDao, null); + final RyaStatement stmtNewP_MisC_Noth_z = createRyaStatementUniqueAdd("zs_NewP_MisC", "zp_NewP_MisC", "zo_NewP_MisC", null , parentDao, null); + final RyaStatement stmtMisP_OldC_Noth_a = createRyaStatementUniqueAdd("as_MisP_OldC", "ap_MisP_OldC", "ao_MisP_OldC", LAST_MONTH, null , childDao); + final RyaStatement stmtMisP_OldC_Noth_f = createRyaStatementUniqueAdd("fs_MisP_OldC", "fp_MisP_OldC", "fo_MisP_OldC", LAST_MONTH, null , childDao); + final RyaStatement stmtMisP_OldC_Noth_u = createRyaStatementUniqueAdd("us_MisP_OldC", "up_MisP_OldC", "uo_MisP_OldC", LAST_MONTH, null , childDao); + final RyaStatement stmtMisP_OldC_addP_z = createRyaStatementUniqueAdd("zs_MisP_OldC", "zp_MisP_OldC", "zo_MisP_OldC", LAST_MONTH, null , childDao); + final RyaStatement stmtMisP_NewC_addP_a = createRyaStatementUniqueAdd("as_MisP_NewC", "ap_MisP_NewC", "ao_MisP_NewC", null , null , childDao); + final RyaStatement stmtMisP_NewC_addP_f = createRyaStatementUniqueAdd("fs_MisP_NewC", "fp_MisP_NewC", "fo_MisP_NewC", null , null , childDao); + final RyaStatement stmtMisP_NewC_addP_u = createRyaStatementUniqueAdd("us_MisP_NewC", "up_MisP_NewC", "uo_MisP_NewC", null , null , childDao); + final RyaStatement stmtMisP_NewC_addP_z = createRyaStatementUniqueAdd("zs_MisP_NewC", "zp_MisP_NewC", "zo_MisP_NewC", null , null , childDao); AccumuloRyaUtils.printTable(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, parentConfig); AccumuloRyaUtils.printTable(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/RulesetCopyIT.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/RulesetCopyIT.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/RulesetCopyIT.java index 448a467..ec3f673 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/RulesetCopyIT.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/RulesetCopyIT.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.YESTERDAY; import static org.apache.rya.accumulo.mr.merge.util.ToolConfigUtils.makeArgument; @@ -110,15 +108,15 @@ public class RulesetCopyIT { prefixes.put("rdf:", RDF.NAMESPACE); prefixes.put("rdfs:", RDFS.NAMESPACE); prefixes.put("owl:", OWL.NAMESPACE); - StringBuilder sb = new StringBuilder(); - for (String prefix : prefixes.keySet()) { + final StringBuilder sb = new StringBuilder(); + for (final String prefix : prefixes.keySet()) { sb.append("PREFIX " + prefix + " <" + prefixes.get(prefix) + ">\n"); } QUERY_PREFIXES = sb.toString(); } - private static RyaURI substitute(String uri) { - for (String prefix : prefixes.keySet()) { + private static RyaURI substitute(final String uri) { + for (final String prefix : prefixes.keySet()) { if (uri.startsWith(prefix)) { return new RyaURI(uri.replace(prefix, prefixes.get(prefix))); } @@ -126,21 +124,21 @@ public class RulesetCopyIT { return new RyaURI(uri); } - private static RyaStatement statement(String s, String p, RyaType o) { - RyaStatement ryaStatement = new RyaStatement(substitute(s), substitute(p), o); + private static RyaStatement statement(final String s, final String p, final RyaType o) { + final RyaStatement ryaStatement = new RyaStatement(substitute(s), substitute(p), o); ryaStatement.setTimestamp(YESTERDAY.getTime()); return ryaStatement; } - private static RyaStatement statement(String s, String p, String o) { + private static RyaStatement statement(final String s, final String p, final String o) { return statement(s, p, substitute(o)); } - private static RyaType literal(String lit) { + private static RyaType literal(final String lit) { return new RyaType(lit); } - private static RyaType literal(String lit, URI type) { + private static RyaType literal(final String lit, final URI type) { return new RyaType(type, lit); } @@ -175,15 +173,15 @@ public class RulesetCopyIT { accumuloDualInstanceDriver.tearDown(); } - private AccumuloRyaDAO runRulesetCopyTest(RyaStatement[] solutionStatements, RyaStatement[] copyStatements, - RyaStatement[] irrelevantStatements, String query, int numSolutions, boolean infer) throws Exception { + private AccumuloRyaDAO runRulesetCopyTest(final RyaStatement[] solutionStatements, final RyaStatement[] copyStatements, + final RyaStatement[] irrelevantStatements, final String query, final int numSolutions, final boolean infer) throws Exception { log.info("Adding data to parent..."); parentDao.add(Arrays.asList(solutionStatements).iterator()); parentDao.add(Arrays.asList(copyStatements).iterator()); parentDao.add(Arrays.asList(irrelevantStatements).iterator()); log.info("Copying from parent tables:"); - for (String table : accumuloDualInstanceDriver.getParentTableList()) { + for (final String table : accumuloDualInstanceDriver.getParentTableList()) { AccumuloRyaUtils.printTablePretty(table, parentConfig, false); } @@ -211,55 +209,55 @@ public class RulesetCopyIT { makeArgument(RdfCloudTripleStoreConfiguration.CONF_INFER, Boolean.toString(infer)) }); - Configuration toolConfig = rulesetTool.getConf(); + final Configuration toolConfig = rulesetTool.getConf(); childConfig.set(MRUtils.AC_ZK_PROP, toolConfig.get(MRUtils.AC_ZK_PROP + CHILD_SUFFIX)); MergeTool.setDuplicateKeys(childConfig); log.info("Finished running tool."); // Child instance has now been created - Connector childConnector = ConfigUtils.getConnector(childConfig); + final Connector childConnector = ConfigUtils.getConnector(childConfig); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setConnector(childConnector); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpTables(); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpDao(); - AccumuloRyaDAO childDao = accumuloDualInstanceDriver.getChildDao(); + final AccumuloRyaDAO childDao = accumuloDualInstanceDriver.getChildDao(); log.info("Resulting child tables:"); - for (String table : accumuloDualInstanceDriver.getChildTableList()) { + for (final String table : accumuloDualInstanceDriver.getChildTableList()) { AccumuloRyaUtils.printTablePretty(table, childConfig, false); } - for (RyaStatement solution : solutionStatements) { - Statement stmt = RyaToRdfConversions.convertStatement(solution); + for (final RyaStatement solution : solutionStatements) { + final Statement stmt = RyaToRdfConversions.convertStatement(solution); TestUtils.assertStatementInInstance("Child missing solution statement " + stmt, 1, solution, childDao, childConfig); } - for (RyaStatement copied : copyStatements) { - Statement stmt = RyaToRdfConversions.convertStatement(copied); + for (final RyaStatement copied : copyStatements) { + final Statement stmt = RyaToRdfConversions.convertStatement(copied); TestUtils.assertStatementInInstance("Child missing relevant statement " + stmt, 1, copied, childDao, childConfig); } - for (RyaStatement irrelevant : irrelevantStatements) { - Statement stmt = RyaToRdfConversions.convertStatement(irrelevant); + for (final RyaStatement irrelevant : irrelevantStatements) { + final Statement stmt = RyaToRdfConversions.convertStatement(irrelevant); TestUtils.assertStatementInInstance("Should not have copied irrelevant statement " + stmt, 0, irrelevant, childDao, childConfig); } - Set<BindingSet> parentSolutions = runQuery(query, parentConfig); + final Set<BindingSet> parentSolutions = runQuery(query, parentConfig); if (parentSolutions.isEmpty()) { log.info("No solutions to query in parent"); } else { - for (BindingSet bs : parentSolutions) { + for (final BindingSet bs : parentSolutions) { log.info("Parent yields query solution: " + bs); } } - Set<BindingSet> childSolutions = runQuery(query, childConfig); + final Set<BindingSet> childSolutions = runQuery(query, childConfig); if (childSolutions.isEmpty()) { log.info("No solutions to query in child"); } else { - for (BindingSet bs : childSolutions) { + for (final BindingSet bs : childSolutions) { log.info("Child yields query solution: " + bs); } } @@ -268,16 +266,16 @@ public class RulesetCopyIT { return childDao; } - private Set<BindingSet> runQuery(String query, Configuration conf) throws Exception { + private Set<BindingSet> runQuery(final String query, final Configuration conf) throws Exception { SailRepository repository = null; SailRepositoryConnection conn = null; try { - Sail extSail = RyaSailFactory.getInstance(conf); + final Sail extSail = RyaSailFactory.getInstance(conf); repository = new SailRepository(extSail); repository.initialize(); conn = repository.getConnection(); - ResultHandler handler = new ResultHandler(); - TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); + final ResultHandler handler = new ResultHandler(); + final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); tq.evaluate(handler); return handler.getSolutions(); } @@ -292,32 +290,32 @@ public class RulesetCopyIT { } private static class ResultHandler implements TupleQueryResultHandler { - private Set<BindingSet> solutions = new HashSet<>(); + private final Set<BindingSet> solutions = new HashSet<>(); public Set<BindingSet> getSolutions() { return solutions; } @Override - public void startQueryResult(List<String> arg0) throws TupleQueryResultHandlerException { + public void startQueryResult(final List<String> arg0) throws TupleQueryResultHandlerException { } @Override - public void handleSolution(BindingSet arg0) throws TupleQueryResultHandlerException { + public void handleSolution(final BindingSet arg0) throws TupleQueryResultHandlerException { solutions.add(arg0); } @Override public void endQueryResult() throws TupleQueryResultHandlerException { } @Override - public void handleBoolean(boolean arg0) throws QueryResultHandlerException { + public void handleBoolean(final boolean arg0) throws QueryResultHandlerException { } @Override - public void handleLinks(List<String> arg0) throws QueryResultHandlerException { + public void handleLinks(final List<String> arg0) throws QueryResultHandlerException { } } @Test public void testRulesetCopyTool() throws Exception { // Should be copied and are involved in the solution: - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:FullProfessor1", "rdf:type", "test:FullProfessor"), statement("test:GraduateStudent1", "test:advisor", "test:FullProfessor1"), statement("test:FullProfessor1", "test:telephone", literal("123-456-7890")), @@ -327,7 +325,7 @@ public class RulesetCopyIT { statement("test:University1", "geo:asWKT", literal("Point(-77.03524 38.889468)", new URIImpl("http://www.opengis.net/ont/geosparql#wktLiteral"))) }; // These aren't solutions but should be copied: - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { statement("test:FullProfessor2", "rdf:type", "test:FullProfessor"), statement("test:GraduateStudent1", "test:advisor", "test:AssistantProfessor1"), statement("test:GraduateStudent1", "test:telephone", literal("555-123-4567")), @@ -335,7 +333,7 @@ public class RulesetCopyIT { statement("test:University1", "test:telephone", literal("800-123-4567")) }; // Should not be copied: - RyaStatement[] irrelevantStatements = { + final RyaStatement[] irrelevantStatements = { statement("test:GraduateStudent2", "test:advisor", "test:FullProfessor1"), statement("test:UndergraduateStudent1", "rdf:type", "test:UndergraduateStudent"), statement("test:UndergraduateStudent2", "rdf:type", "test:UndergraduateStudent"), @@ -354,7 +352,7 @@ public class RulesetCopyIT { statement("test:University1", "test:employs", "test:FullProfessor2") }; - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" + " test:GraduateStudent1 test:advisor ?person .\n" + " ?person rdf:type test:FullProfessor .\n" + " ?person test:telephone ?number .\n" @@ -369,14 +367,14 @@ public class RulesetCopyIT { // + " FILTER(tempo:after(?time, '2000-01-01T01:01:03-08:00'))\n" + "}"; - int parentNamespaceCount = 2; + final int parentNamespaceCount = 2; int childNamespaceCount = 0; parentDao.addNamespace("ns1", "http://www.example.com/ns1#"); parentDao.addNamespace("ns2", "http://www.example.com/ns2#"); // Run the test - AccumuloRyaDAO childDao = runRulesetCopyTest(solutionStatements, copyStatements, irrelevantStatements, query, 1, false); + final AccumuloRyaDAO childDao = runRulesetCopyTest(solutionStatements, copyStatements, irrelevantStatements, query, 1, false); // Verify namespaces were copied - CloseableIteration<Namespace, RyaDAOException> nsIter = childDao.iterateNamespace(); + final CloseableIteration<Namespace, RyaDAOException> nsIter = childDao.iterateNamespace(); while (nsIter.hasNext()) { childNamespaceCount++; nsIter.next(); @@ -390,13 +388,13 @@ public class RulesetCopyIT { */ @Test public void testRulesetCopyHierarchy() throws Exception { - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:p1", "rdf:type", "test:Professor"), statement("test:p1", "test:worksFor", "test:Department0"), statement("test:p2", "rdf:type", "test:FullProfessor"), statement("test:p2", "test:headOf", "test:Department0"), }; - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { // schema: statement("test:Professor", "rdfs:subClassOf", "test:Person"), statement("test:Student", "rdfs:subClassOf", "test:Person"), @@ -410,7 +408,7 @@ public class RulesetCopyIT { statement("test:ap1", "rdf:type", "test:AssistantProfessor"), statement("test:gs1", "rdf:type", "test:GraduateStudent"), }; - RyaStatement[] otherStatements = { + final RyaStatement[] otherStatements = { // schema: statement("test:worksFor", "rdfs:subPropertyOf", "test:affiliatedWith"), statement("test:Person", "rdfs:subClassOf", "test:Animal"), @@ -418,7 +416,7 @@ public class RulesetCopyIT { statement("test:University0", "test:hasSubOrganizationOf", "test:Department0"), statement("test:a1", "rdf:type", "test:Animal") }; - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" + " ?X rdf:type test:Person .\n" + " ?X test:memberOf test:Department0 .\n" + "}"; @@ -431,7 +429,7 @@ public class RulesetCopyIT { */ @Test public void testRulesetCopySameAs() throws Exception { - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" + " {\n" + " ?X test:worksFor test:Department0 .\n" + " ?X rdf:type test:Student\n" @@ -440,7 +438,7 @@ public class RulesetCopyIT { + " test:p1 test:worksFor test:CSDept .\n" + " }\n" + "}"; - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:s1", "test:worksFor", "test:CSDept"), statement("test:s1", "rdf:type", "test:Student"), statement("test:p1", "rdf:type", "test:Professor"), @@ -449,12 +447,12 @@ public class RulesetCopyIT { statement("test:p1", "owl:sameAs", "alt:p1"), statement("test:JohnDoe", "owl:sameAs", "alt:p1") }; - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { statement("test:s2", "rdf:type", "test:Student"), statement("alt:s2", "test:worksFor", "test:CSDept"), statement("test:s3", "test:worksFor", "test:CSDept") }; - RyaStatement[] otherStatements = { + final RyaStatement[] otherStatements = { // sameAs inference only expands constants: statement("test:s2", "owl:sameAs", "alt:s2"), // sameAs inference not applied to rdf:type statements: @@ -472,12 +470,12 @@ public class RulesetCopyIT { */ @Test public void testRulesetCopyTransitive() throws Exception { - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" // Note: we get spurious results if the order of these are switched (see RYA-71): + " ?X test:subOrganizationOf test:University0 .\n" + " ?X rdf:type test:ResearchGroup .\n" + "}"; - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:subOrganizationOf", "rdf:type", "owl:TransitiveProperty"), statement("test:ResearchGroup0", "rdf:type", "test:ResearchGroup"), statement("test:ResearchGroup0", "test:subOrganizationOf", "test:Department0"), @@ -485,14 +483,14 @@ public class RulesetCopyIT { statement("test:Subgroup0", "rdf:type", "test:ResearchGroup"), statement("test:Subgroup0", "test:subOrganizationOf", "test:ResearchGroup0") }; - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { statement("test:ResearchGroupA", "rdf:type", "test:ResearchGroup"), statement("test:ResearchGroupA", "test:subOrganizationOf", "test:DepartmentA"), statement("test:DepartmentA", "test:subOrganizationOf", "test:UniversityA"), statement("test:OtherGroup0", "test:subOrganizationOf", "test:Department0"), statement("test:Department1", "test:subOrganizationOf", "test:University0") }; - RyaStatement[] otherStatements = { + final RyaStatement[] otherStatements = { statement("test:University0", "rdf:type", "test:University"), statement("test:Department0", "test:affiliatedWith", "test:University0") }; @@ -506,11 +504,11 @@ public class RulesetCopyIT { */ @Test public void testRulesetCopyInverse() throws Exception { - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" + " ?X rdf:type test:Person .\n" + " test:University0 test:hasAlumnus ?X .\n" + "}"; - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:s1", "rdf:type", "test:Person"), statement("test:p1", "rdf:type", "test:Person"), statement("test:s1", "test:undergraduateDegreeFrom", "test:University0"), @@ -519,11 +517,11 @@ public class RulesetCopyIT { statement("test:doctoralDegreeFrom", "rdfs:subPropertyOf", "test:degreeFrom"), statement("test:hasAlumnus", "owl:inverseOf", "test:degreeFrom") }; - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { statement("test:mastersDegreeFrom", "rdfs:subPropertyOf", "test:degreeFrom"), statement("test:s2", "test:mastersDegreeFrom", "test:University0"), }; - RyaStatement[] otherStatements = { + final RyaStatement[] otherStatements = { statement("test:p1", "test:mastersDegreeFrom", "test:University1"), }; runRulesetCopyTest(solutionStatements, copyStatements, otherStatements, query, 2, true); @@ -535,11 +533,11 @@ public class RulesetCopyIT { */ @Test public void testRulesetCopySymmetry() throws Exception { - String query = QUERY_PREFIXES + "SELECT * {\n" + final String query = QUERY_PREFIXES + "SELECT * {\n" + " ?X rdf:type test:Person .\n" + " ?X test:knows test:Alice .\n" + "}"; - RyaStatement[] solutionStatements = { + final RyaStatement[] solutionStatements = { statement("test:Alice", "test:knows", "test:Bob"), statement("test:Alice", "test:friendsWith", "test:Carol"), statement("test:Bob", "rdf:type", "test:Person"), @@ -547,11 +545,11 @@ public class RulesetCopyIT { statement("test:friendsWith", "rdfs:subPropertyOf", "test:knows"), statement("test:knows", "rdf:type", "owl:SymmetricProperty") }; - RyaStatement[] copyStatements = { + final RyaStatement[] copyStatements = { statement("test:Alice", "rdf:type", "test:Person"), statement("test:Eve", "rdf:type", "test:Person") }; - RyaStatement[] otherStatements = { + final RyaStatement[] otherStatements = { statement("test:Carol", "test:knows", "test:Eve"), statement("test:Bob", "test:friendsWith", "test:Carol") }; http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/1d33b435/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/demo/CopyToolDemo.java ---------------------------------------------------------------------- diff --git a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/demo/CopyToolDemo.java b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/demo/CopyToolDemo.java index 5879dc5..e789c5f 100644 --- a/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/demo/CopyToolDemo.java +++ b/extras/rya.merger/src/test/java/org/apache/rya/accumulo/mr/merge/demo/CopyToolDemo.java @@ -1,24 +1,22 @@ -package org.apache.rya.accumulo.mr.merge.demo; - /* - * #%L - * org.apache.rya.accumulo.mr.merge - * %% - * Copyright (C) 2014 Rya - * %% - * Licensed 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 + * 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 + * 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. - * #L% + * 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.accumulo.mr.merge.demo; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.LAST_MONTH; import static org.apache.rya.accumulo.mr.merge.util.TestUtils.TODAY; @@ -97,13 +95,13 @@ public class CopyToolDemo { private AccumuloDualInstanceDriver accumuloDualInstanceDriver; private CopyTool copyTool = null; - public static void main(String args[]) { + public static void main(final String args[]) { DemoUtilities.setupLogging(LOGGING_DETAIL); log.info("Setting up Copy Tool Demo"); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override - public void uncaughtException(Thread thread, Throwable throwable) { + public void uncaughtException(final Thread thread, final Throwable throwable) { log.fatal("Uncaught exception in " + thread.getName(), throwable); } }); @@ -115,7 +113,7 @@ public class CopyToolDemo { log.info("Shutting down..."); try { copyToolDemo.tearDown(); - } catch (Exception e) { + } catch (final Exception e) { log.error("Error while shutting down", e); } finally { log.info("Done shutting down"); @@ -126,12 +124,12 @@ public class CopyToolDemo { try { copyToolDemo.setUp(); copyToolDemo.testCopyTool(); - } catch (Exception e) { + } catch (final Exception e) { log.error("Error while testing copy tool", e); } finally { try { copyToolDemo.tearDown(); - } catch (Exception e) { + } catch (final Exception e) { log.error("Error shutting down copy tool", e); } } @@ -162,7 +160,7 @@ public class CopyToolDemo { } } - private void copyToolRun(Date startDate) throws AccumuloException, AccumuloSecurityException { + private void copyToolRun(final Date startDate) throws AccumuloException, AccumuloSecurityException { copyTool = new CopyTool(); copyTool.setupAndRun(new String[] { makeArgument(MRUtils.AC_MOCK_PROP, Boolean.toString(IS_MOCK)), @@ -195,17 +193,17 @@ public class CopyToolDemo { makeArgument(MergeTool.START_TIME_PROP, MergeTool.getStartTimeString(startDate, IS_START_TIME_DIALOG_ENABLED)) }); - Configuration toolConfig = copyTool.getConf(); - String zooKeepers = toolConfig.get(MRUtils.AC_ZK_PROP + CHILD_SUFFIX); + final Configuration toolConfig = copyTool.getConf(); + final String zooKeepers = toolConfig.get(MRUtils.AC_ZK_PROP + CHILD_SUFFIX); MergeTool.setDuplicateKeysForProperty(childConfig, MRUtils.AC_ZK_PROP, zooKeepers); if (USE_COPY_FILE_OUTPUT) { // Set up the child tables now to test importing the files back into the child instance - String childTableName = CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX; + final String childTableName = CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX; try { copyTool.createTableIfNeeded(childTableName); copyTool.importFilesToChildTable(childTableName); - } catch (Exception e) { + } catch (final Exception e) { log.error("Failed to import files into child instance.", e); } } @@ -218,33 +216,33 @@ public class CopyToolDemo { log.info("Setting up initial state of parent before copying to child..."); log.info("Adding data to parent..."); - int numRowsNotToCopy = 80; - int numRowsToCopy = 20; + final int numRowsNotToCopy = 80; + final int numRowsToCopy = 20; // Create Rya Statement before last month which won't be copied - Random random = new Random(); + final Random random = new Random(); for (int i = 1; i <= numRowsNotToCopy; i++) { - long randTimeBeforeLastMonth = DemoUtilities.randLong(0, LAST_MONTH.getTime()); - String randVis = random.nextBoolean() ? PARENT_AUTH : ""; - RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("Nobody", "sees", "me " + i, new Date(randTimeBeforeLastMonth)); + final long randTimeBeforeLastMonth = DemoUtilities.randLong(0, LAST_MONTH.getTime()); + final String randVis = random.nextBoolean() ? PARENT_AUTH : ""; + final RyaStatement ryaStatementOutOfTimeRange = createRyaStatement("Nobody", "sees", "me " + i, new Date(randTimeBeforeLastMonth)); ryaStatementOutOfTimeRange.setColumnVisibility(randVis.getBytes()); parentDao.add(ryaStatementOutOfTimeRange); } for (int i = 1; i <= numRowsToCopy; i++) { - long randTimeAfterYesterdayAndBeforeToday = DemoUtilities.randLong(YESTERDAY.getTime(), TODAY.getTime()); - String randVis = random.nextBoolean() ? PARENT_AUTH : ""; - RyaStatement ryaStatementShouldCopy = createRyaStatement("bob", "copies", "susan " + i, new Date(randTimeAfterYesterdayAndBeforeToday)); + final long randTimeAfterYesterdayAndBeforeToday = DemoUtilities.randLong(YESTERDAY.getTime(), TODAY.getTime()); + final String randVis = random.nextBoolean() ? PARENT_AUTH : ""; + final RyaStatement ryaStatementShouldCopy = createRyaStatement("bob", "copies", "susan " + i, new Date(randTimeAfterYesterdayAndBeforeToday)); ryaStatementShouldCopy.setColumnVisibility(randVis.getBytes()); parentDao.add(ryaStatementShouldCopy); } if (USE_COPY_FILE_OUTPUT) { // Set up table splits - SortedSet<Text> splits = new TreeSet<>(); + final SortedSet<Text> splits = new TreeSet<>(); for (char alphabet = 'a'; alphabet <= 'e'; alphabet++) { - Text letter = new Text(alphabet + ""); + final Text letter = new Text(alphabet + ""); splits.add(letter); } parentDao.getConnector().tableOperations().addSplits(PARENT_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, splits); @@ -273,8 +271,8 @@ public class CopyToolDemo { // Copy Tool made child instance so hook the tables and dao into the driver. - String childUser = accumuloDualInstanceDriver.getChildUser(); - Connector childConnector = ConfigUtils.getConnector(childConfig); + final String childUser = accumuloDualInstanceDriver.getChildUser(); + final Connector childConnector = ConfigUtils.getConnector(childConfig); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setConnector(childConnector); accumuloDualInstanceDriver.getChildAccumuloInstanceDriver().setUpTables(); @@ -283,13 +281,13 @@ public class CopyToolDemo { // Update child config to include changes made from copy process - SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); - Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH); + final SecurityOperations childSecOps = accumuloDualInstanceDriver.getChildSecOps(); + final Authorizations newChildAuths = AccumuloRyaUtils.addUserAuths(childUser, childSecOps, PARENT_AUTH); childSecOps.changeUserAuthorizations(childUser, newChildAuths); - String childAuthString = newChildAuths.toString(); - List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); + final String childAuthString = newChildAuths.toString(); + final List<String> duplicateKeys = MergeTool.DUPLICATE_KEY_MAP.get(MRUtils.AC_AUTH_PROP); childConfig.set(MRUtils.AC_AUTH_PROP, childAuthString); - for (String key : duplicateKeys) { + for (final String key : duplicateKeys) { childConfig.set(key, childAuthString); } @@ -298,8 +296,8 @@ public class CopyToolDemo { //AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX, childConfig); AccumuloRyaUtils.printTablePretty(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); - Iterator<Entry<Key, Value>> iterator = scanner.iterator(); + final Scanner scanner = AccumuloRyaUtils.getScanner(CHILD_TABLE_PREFIX + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, childConfig); + final Iterator<Entry<Key, Value>> iterator = scanner.iterator(); int count = 0; while (iterator.hasNext()) { iterator.next();
