http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapter.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapter.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapter.java new file mode 100644 index 0000000..47e740d --- /dev/null +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapter.java @@ -0,0 +1,67 @@ +/* + * 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.export.api.conf; + +import org.apache.rya.export.JAXBAccumuloMergeConfiguration; +import org.apache.rya.export.accumulo.common.InstanceType; +import org.apache.rya.export.api.conf.AccumuloMergeConfiguration.AccumuloBuilder; + +/** + * Helper for creating the immutable application configuration that uses + * Accumulo. + */ +public class AccumuloConfigurationAdapter { + /** + * @param jConfig - The JAXB generated configuration. + * @return The {@link MergeConfiguration} used in the application + * @throws MergeConfigurationException + */ + public static AccumuloMergeConfiguration createConfig(final JAXBAccumuloMergeConfiguration jConfig) throws MergeConfigurationException { + final AccumuloBuilder configBuilder = (AccumuloBuilder) new AccumuloBuilder() + // Accumulo Properties + .setParentZookeepers(jConfig.getParentZookeepers()) + .setParentAuths(jConfig.getParentAuths()) + .setParentInstanceType(InstanceType.fromName(jConfig.getParentInstanceType())) + .setChildZookeepers(jConfig.getChildZookeepers()) + .setChildAuths(jConfig.getChildAuths()) + .setChildInstanceType(InstanceType.fromName(jConfig.getChildInstanceType())) + // Base Properties + .setParentHostname(jConfig.getParentHostname()) + .setParentUsername(jConfig.getParentUsername()) + .setParentPassword(jConfig.getParentPassword()) + .setParentRyaInstanceName(jConfig.getParentRyaInstanceName()) + .setParentDBType(jConfig.getParentDBType()) + .setParentPort(jConfig.getParentPort()) + .setParentTablePrefix(jConfig.getParentTablePrefix()) + .setParentTomcatUrl(jConfig.getParentTomcatUrl()) + .setChildHostname(jConfig.getChildHostname()) + .setChildUsername(jConfig.getChildUsername()) + .setChildPassword(jConfig.getChildPassword()) + .setChildRyaInstanceName(jConfig.getChildRyaInstanceName()) + .setChildDBType(jConfig.getChildDBType()) + .setChildPort(jConfig.getChildPort()) + .setChildTablePrefix(jConfig.getChildTablePrefix()) + .setChildTomcatUrl(jConfig.getChildTomcatUrl()) + .setMergePolicy(jConfig.getMergePolicy()) + .setUseNtpServer(jConfig.isUseNtpServer()) + .setNtpServerHost(jConfig.getNtpServerHost()) + .setToolStartTime(jConfig.getToolStartTime()); + return configBuilder.build(); + } +}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java new file mode 100644 index 0000000..fbd5477 --- /dev/null +++ b/extras/rya.export/export.accumulo/src/main/java/org/apache/rya/export/api/conf/AccumuloMergeConfiguration.java @@ -0,0 +1,182 @@ +/* + * 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.export.api.conf; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.http.annotation.Immutable; +import org.apache.rya.export.accumulo.common.InstanceType; + +/** + * Immutable configuration object to allow the MergeTool to connect to the parent and child + * databases for data merging. + */ +@Immutable +public class AccumuloMergeConfiguration extends MergeConfiguration { + /** + * Information needed to connect to the parent database + */ + private final String parentZookeepers; + private final String parentAuths; + private final InstanceType parentInstanceType; + + /** + * Information needed to connect to the child database + */ + private final String childZookeepers; + private final String childAuths; + private final InstanceType childInstanceType; + + /** + * Constructs a {@link AccumuloMergeConfiguration}. All fields are required. + */ + private AccumuloMergeConfiguration(final AccumuloBuilder builder) throws MergeConfigurationException { + super(checkNotNull(builder)); + try { + this.parentZookeepers = checkNotNull(builder.parentZookeepers); + this.parentAuths = checkNotNull(builder.parentAuths); + this.parentInstanceType = checkNotNull(builder.parentInstanceType); + this.childZookeepers = checkNotNull(builder.childZookeepers); + this.childAuths = checkNotNull(builder.childAuths); + this.childInstanceType = checkNotNull(builder.childInstanceType); + } catch(final NullPointerException npe) { + throw new MergeConfigurationException("The configuration was missing required field(s)", npe); + } + } + + /** + * @return the Zookeeper host names of the parent used by Accumulo. + */ + public String getParentZookeepers() { + return parentZookeepers; + } + + /** + * @return the Accumulo user authorizations of the parent. + */ + public String getParentAuths() { + return parentAuths; + } + + /** + * @return the Accumulo instance type of the parent. + */ + public InstanceType getParentInstanceType() { + return parentInstanceType; + } + + /** + * @return the Zookeeper host names of the child used by Accumulo. + */ + public String getChildZookeepers() { + return childZookeepers; + } + + /** + * @return the Accumulo user authorizations of the child. + */ + public String getChildAuths() { + return childAuths; + } + + /** + * @return the Accumulo instance type of the child. + */ + public InstanceType getChildInstanceType() { + return childInstanceType; + } + + /** + * Builder to help create {@link MergeConfiguration}s. + */ + public static class AccumuloBuilder extends MergeConfiguration.Builder { + private String parentZookeepers; + private String parentAuths; + private InstanceType parentInstanceType; + + private String childZookeepers; + private String childAuths; + private InstanceType childInstanceType; + + public AccumuloBuilder() { + super(); + } + + /** + * @param zookeepers - the Zookeeper host names of the parent used by + * Accumulo. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setParentZookeepers(final String zookeepers) { + parentZookeepers = zookeepers; + return this; + } + + /** + * @param auths - the Accumulo user authorizations of the parent. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setParentAuths(final String auths) { + parentAuths = auths; + return this; + } + + /** + * @param instanceType the Accumulo instance type of the parent. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setParentInstanceType(final InstanceType instanceType) { + parentInstanceType = instanceType; + return this; + } + + /** + * @param zookeepers - the Zookeeper host names of the child used by + * Accumulo. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setChildZookeepers(final String zookeepers) { + childZookeepers = zookeepers; + return this; + } + + /** + * @param auths - the Accumulo user authorizations of the child. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setChildAuths(final String auths) { + childAuths = auths; + return this; + } + + /** + * @params instanceType - the Accumulo instance type of the child. + * @return the updated {@link AccumuloBuilder}. + */ + public AccumuloBuilder setChildInstanceType(final InstanceType instanceType) { + childInstanceType = instanceType; + return this; + } + + @Override + public AccumuloMergeConfiguration build() throws MergeConfigurationException { + return new AccumuloMergeConfiguration(this); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/main/xsd/AccumuloMergeConfiguration.xsd ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/main/xsd/AccumuloMergeConfiguration.xsd b/extras/rya.export/export.accumulo/src/main/xsd/AccumuloMergeConfiguration.xsd new file mode 100644 index 0000000..65d1ed5 --- /dev/null +++ b/extras/rya.export/export.accumulo/src/main/xsd/AccumuloMergeConfiguration.xsd @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +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. +--> +<schema xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:mc="http://mergeconfig" + targetNamespace="http://mergeconfig" + elementFormDefault="qualified"> + + <!-- Reference to External Module containing JAXBMergeConfiguration definition --> + <xs:include schemaLocation="../../../../export.api/src/main/xsd/MergeConfiguration.xsd"/> + + <xs:complexType name="JAXBAccumuloMergeConfiguration"> + <xs:complexContent> + <xs:extension base="mc:JAXBMergeConfiguration"> + <xs:sequence> + <!-- Parent Properties --> + <xs:element name="parentZookeepers" type="xs:string"/> + <xs:element name="parentAuths" type="xs:string"/> + <xs:element name="parentInstanceType" type="xs:string"/> + + <!-- Child Properties --> + <xs:element name="childZookeepers" type="xs:string"/> + <xs:element name="childAuths" type="xs:string"/> + <xs:element name="childInstanceType" type="xs:string"/> + </xs:sequence> + </xs:extension> + </xs:complexContent> + </xs:complexType> +</schema> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStoreTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStoreTest.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStoreTest.java new file mode 100644 index 0000000..22df92a --- /dev/null +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/AccumuloRyaStatementStoreTest.java @@ -0,0 +1,384 @@ +/* + * 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.export.accumulo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Date; +import java.util.Iterator; + +import org.apache.hadoop.conf.Configuration; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.rya.export.MergePolicy; +import org.apache.rya.export.accumulo.common.InstanceType; +import org.apache.rya.export.accumulo.conf.AccumuloExportConstants; +import org.apache.rya.export.accumulo.util.AccumuloInstanceDriver; +import org.apache.rya.export.api.MergerException; +import org.apache.rya.export.api.conf.AccumuloMergeConfiguration; +import org.apache.rya.export.api.store.AddStatementException; +import org.apache.rya.export.api.store.FetchStatementException; +import org.apache.rya.export.api.store.RemoveStatementException; +import org.apache.rya.export.api.store.UpdateStatementException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.google.common.collect.ImmutableList; + +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.indexing.accumulo.ConfigUtils; + +/** + * Tests the methods of {@link AccumuloRyaStatementStore}. + */ +public class AccumuloRyaStatementStoreTest { + private static final Logger log = LogManager.getLogger(AccumuloRyaStatementStoreTest.class); + private static final InstanceType INSTANCE_TYPE = InstanceType.MOCK; + + private static final boolean IS_MOCK = INSTANCE_TYPE.isMock(); + private static final String USER_NAME = IS_MOCK ? "test_user" : AccumuloInstanceDriver.ROOT_USER_NAME; + private static final String PASSWORD = "password"; + private static final String INSTANCE_NAME = "test_instance"; + private static final String AUTHS = "test_auth"; + private static final String RYA_TABLE_PREFIX = "test_"; + private static final String ZOOKEEPERS = "localhost"; + + // Rya data store and connections. + private static AccumuloInstanceDriver accumuloInstanceDriver = null; + + private static final Date DATE = new Date(); + + private static final ImmutableList<RyaStatement> RYA_STATEMENTS = ImmutableList.of( + TestUtils.createRyaStatement("Adam", "analyzes", "apple", DATE), + TestUtils.createRyaStatement("Bob", "bites", "burger", DATE), + TestUtils.createRyaStatement("Charlie", "checks", "chores", DATE), + TestUtils.createRyaStatement("Debbie", "drives", "deal", DATE), + TestUtils.createRyaStatement("Emma", "eats", "everything", DATE) + ); + + @BeforeClass + public static void setupResources() throws Exception { + // Initialize the Accumulo instance that will be used to store Triples and get a connection to it. + accumuloInstanceDriver = startAccumuloInstanceDriver(); + } + + @Before + public void setUpPerTest() throws Exception { + accumuloInstanceDriver.setUpTables(); + accumuloInstanceDriver.setUpDao(); + accumuloInstanceDriver.setUpConfig(); + } + + @After + public void tearDownPerTest() throws Exception { + log.info("tearDownPerTest(): tearing down now."); + accumuloInstanceDriver.tearDownTables(); + accumuloInstanceDriver.tearDownDao(); + } + + @AfterClass + public static void tearDownPerClass() throws Exception { + log.info("tearDownPerClass(): tearing down now."); + accumuloInstanceDriver.tearDown(); + } + + @Test + public void testFetchStatements() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + accumuloRyaStatementStore.fetchStatements(); + } + + @Test (expected = FetchStatementException.class) + public void testFetchStatements_FetchWrongInstance() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final Configuration config = accumuloRyaStatementStore.getRyaDAO().getConf(); + + config.set(ConfigUtils.CLOUDBASE_INSTANCE, "wrong instance"); + + accumuloRyaStatementStore.fetchStatements(); + } + + @Test + public void testAddStatement() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + } + + @Test (expected = AddStatementException.class) + public void testAddStatement_AddNull() throws Exception { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + accumuloRyaStatementStore.addStatement(null); + } + + @Test + public void testRemoveStatement() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + // Add one then remove it right away + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + accumuloRyaStatementStore.removeStatement(ryaStatement); + assertTrue(isStatementStoreEmpty(accumuloRyaStatementStore)); + } + + // Add all then remove all + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.removeStatement(ryaStatement); + } + assertTrue(isStatementStoreEmpty(accumuloRyaStatementStore)); + + // Add all then remove all in reverse order + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + final ImmutableList<RyaStatement> reverseList = RYA_STATEMENTS.reverse(); + for (final RyaStatement ryaStatement : reverseList) { + accumuloRyaStatementStore.removeStatement(ryaStatement); + } + assertTrue(isStatementStoreEmpty(accumuloRyaStatementStore)); + + // Add all then remove one from middle follow by another before and + // after the first removed one + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final RyaStatement firstToRemove = RYA_STATEMENTS.get(2); + final RyaStatement before = RYA_STATEMENTS.get(1); + final RyaStatement after = RYA_STATEMENTS.get(3); + + accumuloRyaStatementStore.removeStatement(firstToRemove); + accumuloRyaStatementStore.removeStatement(before); + accumuloRyaStatementStore.removeStatement(after); + } + + @Test (expected = RemoveStatementException.class) + public void testRemoveStatement_RemoveNull() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + accumuloRyaStatementStore.removeStatement(null); + } + + @Test + public void testRemoveStatement_RemoveStatementNotFound() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final RyaStatement notFoundStatement = TestUtils.createRyaStatement("Statement", "not found", "here", DATE); + accumuloRyaStatementStore.removeStatement(notFoundStatement); + } + + @Test + public void testUpdateStatement() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final RyaStatement firstRyaStatement = RYA_STATEMENTS.get(0); + final RyaStatement updatedRyaStatement = TestUtils.copyRyaStatement(firstRyaStatement); + + assertEquals(firstRyaStatement, updatedRyaStatement); + + final String subject = TestUtils.convertRyaUriToString(updatedRyaStatement.getSubject()); + final String predicate = TestUtils.convertRyaUriToString(updatedRyaStatement.getPredicate()); + updatedRyaStatement.setSubject(TestUtils.createRyaUri(subject + "_UPDATED")); + updatedRyaStatement.setPredicate(TestUtils.createRyaUri(predicate + "_UPDATED")); + + accumuloRyaStatementStore.updateStatement(firstRyaStatement, updatedRyaStatement); + + final Iterator<RyaStatement> ryaStatementsIterator = accumuloRyaStatementStore.fetchStatements(); + int originalCount = 0; + int updatedCount = 0; + int totalCount = 0; + while (ryaStatementsIterator.hasNext()) { + final RyaStatement ryaStatement = ryaStatementsIterator.next(); + if (ryaStatement.equals(firstRyaStatement)) { + originalCount++; + } + if (ryaStatement.equals(updatedRyaStatement)) { + updatedCount++; + } + totalCount++; + } + + assertEquals(0, originalCount); + assertEquals(1, updatedCount); + assertEquals(RYA_STATEMENTS.size(), totalCount); + } + + @Test (expected = UpdateStatementException.class) + public void testUpdateStatement_UpdateNull() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final RyaStatement firstRyaStatement = RYA_STATEMENTS.get(0); + final RyaStatement updatedRyaStatement = TestUtils.copyRyaStatement(firstRyaStatement); + + assertEquals(firstRyaStatement, updatedRyaStatement); + + final String subject = TestUtils.convertRyaUriToString(updatedRyaStatement.getSubject()); + final String predicate = TestUtils.convertRyaUriToString(updatedRyaStatement.getPredicate()); + updatedRyaStatement.setSubject(TestUtils.createRyaUri(subject + "_UPDATED")); + updatedRyaStatement.setPredicate(TestUtils.createRyaUri(predicate + "_UPDATED")); + + accumuloRyaStatementStore.updateStatement(firstRyaStatement, null); + } + + @Test + public void testUpdateStatement_OriginalNotFound() throws MergerException { + final AccumuloRyaStatementStore accumuloRyaStatementStore = createAccumuloRyaStatementStore(); + + for (final RyaStatement ryaStatement : RYA_STATEMENTS) { + accumuloRyaStatementStore.addStatement(ryaStatement); + } + + final RyaStatement notFoundStatement = TestUtils.createRyaStatement("Statement", "not found", "here", DATE); + final RyaStatement updatedRyaStatement = TestUtils.copyRyaStatement(notFoundStatement); + + assertEquals(notFoundStatement, updatedRyaStatement); + + final String subject = TestUtils.convertRyaUriToString(updatedRyaStatement.getSubject()); + final String predicate = TestUtils.convertRyaUriToString(updatedRyaStatement.getPredicate()); + updatedRyaStatement.setSubject(TestUtils.createRyaUri(subject + "_UPDATED")); + updatedRyaStatement.setPredicate(TestUtils.createRyaUri(predicate + "_UPDATED")); + + accumuloRyaStatementStore.updateStatement(notFoundStatement, updatedRyaStatement); + + final Iterator<RyaStatement> ryaStatementsIterator = accumuloRyaStatementStore.fetchStatements(); + int originalCount = 0; + int updatedCount = 0; + int totalCount = 0; + while (ryaStatementsIterator.hasNext()) { + final RyaStatement ryaStatement = ryaStatementsIterator.next(); + if (ryaStatement.equals(notFoundStatement)) { + originalCount++; + } + if (ryaStatement.equals(updatedRyaStatement)) { + updatedCount++; + } + totalCount++; + } + + assertEquals(0, originalCount); + assertEquals(1, updatedCount); + assertEquals(RYA_STATEMENTS.size() + 1, totalCount); + } + + + + @After + public void shutdownMiniResources() { + if(accumuloInstanceDriver != null) { + try { + log.info("Shutting down the Mini Accumulo being used as a Rya store."); + accumuloInstanceDriver.tearDown(); + log.info("Mini Accumulo being used as a Rya store shut down."); + } catch(final Exception e) { + log.error("Could not shut down the Mini Accumulo.", e); + } + } + } + + private static boolean isStatementStoreEmpty(final AccumuloRyaStatementStore accumuloRyaStatementStore) throws MergerException { + final Iterator<RyaStatement> iterator = accumuloRyaStatementStore.fetchStatements(); + return !iterator.hasNext(); + } + + /** + * Setup a Accumulo instance driver to run the test. Establishes the + * connector to the Accumulo instance. + * @return an {@link AccumuloInstanceDriver}. + * @throws Exception + */ + private static AccumuloInstanceDriver startAccumuloInstanceDriver() throws Exception { + final AccumuloInstanceDriver accumuloInstanceDriver = new AccumuloInstanceDriver("Test Driver", INSTANCE_TYPE, true, false, true, USER_NAME, PASSWORD, INSTANCE_NAME, RYA_TABLE_PREFIX, AUTHS, ZOOKEEPERS); + accumuloInstanceDriver.setUp(); + + return accumuloInstanceDriver; + } + + private static AccumuloMergeConfiguration createAccumuloMergeConfiguration() { + final AccumuloMergeConfiguration accumuloMergeConfiguration = mock(AccumuloMergeConfiguration.class); + + when(accumuloMergeConfiguration.getParentRyaInstanceName()).thenReturn(INSTANCE_NAME); + when(accumuloMergeConfiguration.getParentUsername()).thenReturn(USER_NAME); + when(accumuloMergeConfiguration.getParentPassword()).thenReturn(PASSWORD); + when(accumuloMergeConfiguration.getParentInstanceType()).thenReturn(INSTANCE_TYPE); + when(accumuloMergeConfiguration.getParentTablePrefix()).thenReturn(RYA_TABLE_PREFIX); + when(accumuloMergeConfiguration.getParentAuths()).thenReturn(AUTHS); + + // Other + when(accumuloMergeConfiguration.getMergePolicy()).thenReturn(MergePolicy.TIMESTAMP); + when(accumuloMergeConfiguration.getToolStartTime()).thenReturn(AccumuloExportConstants.convertDateToStartTimeString(new Date())); + + return accumuloMergeConfiguration; + } + + private static AccumuloRyaStatementStore createAccumuloRyaStatementStore() throws MergerException { + final AccumuloMergeConfiguration accumuloMergeConfiguration = createAccumuloMergeConfiguration(); + return createAccumuloRyaStatementStore(accumuloMergeConfiguration); + } + + private static AccumuloRyaStatementStore createAccumuloRyaStatementStore(final AccumuloMergeConfiguration accumuloMergeConfiguration) throws MergerException { + final String instance = accumuloMergeConfiguration.getParentRyaInstanceName(); + final String username = accumuloMergeConfiguration.getParentUsername(); + final String password = accumuloMergeConfiguration.getParentPassword(); + final InstanceType instanceType = accumuloMergeConfiguration.getParentInstanceType(); + final String tablePrefix = accumuloMergeConfiguration.getParentTablePrefix(); + final String auths = accumuloMergeConfiguration.getParentAuths(); + final String zooKeepers = accumuloMergeConfiguration.getParentZookeepers(); + + return new AccumuloRyaStatementStore(instance, username, password, instanceType, tablePrefix, auths, zooKeepers); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java new file mode 100644 index 0000000..41d6495 --- /dev/null +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/TestUtils.java @@ -0,0 +1,80 @@ +/* + * 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.export.accumulo; + +import java.util.Date; + +import org.apache.rya.export.accumulo.util.AccumuloRyaUtils; + +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.api.domain.RyaURI; + +/** + * Utility methods for testing merging/copying. + */ +public final class TestUtils { + private static final String NAMESPACE = "#:"; + + /** + * Creates a {@link RyaURI} for the specified local name. + * @param localName the URI's local name. + * @return the {@link RyraURI}. + */ + public static RyaURI createRyaUri(final String localName) { + return AccumuloRyaUtils.createRyaUri(NAMESPACE, localName); + } + + /** + * Converts a {@link RyaURI} to the contained data string. + * @param namespace the namespace. + * @param the {@link RyaURI} to convert. + * @return the data value without the namespace. + */ + public static String convertRyaUriToString(final RyaURI RyaUri) { + return AccumuloRyaUtils.convertRyaUriToString(NAMESPACE, RyaUri); + } + + /** + * Creates a {@link RyaStatement} from the specified subject, predicate, and object. + * @param subject the subject. + * @param predicate the predicate. + * @param object the object. + * @param date the {@link Date} to use for the key's timestamp. + * @return the {@link RyaStatement}. + */ + public static RyaStatement createRyaStatement(final String subject, final String predicate, final String object, final Date date) { + final RyaURI subjectUri = createRyaUri(subject); + final RyaURI predicateUri = createRyaUri(predicate); + final RyaURI objectUri = createRyaUri(object); + final RyaStatement ryaStatement = new RyaStatement(subjectUri, predicateUri, objectUri); + if (date != null) { + ryaStatement.setTimestamp(date.getTime()); + } + return ryaStatement; + } + + /** + * Copies a {@link RyaStatement} into a new {@link RyaStatement}. + * @param s the {@link RyaStatement} to copy. + * @return the newly copied {@link RyaStatement}. + */ + public static RyaStatement copyRyaStatement(final RyaStatement s) { + return new RyaStatement(s.getSubject(), s.getPredicate(), s.getObject(), s.getContext(), s.getQualifer(), s.getColumnVisibility(), s.getValue(), s.getTimestamp()); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/driver/AccumuloDualInstanceDriver.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/driver/AccumuloDualInstanceDriver.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/driver/AccumuloDualInstanceDriver.java new file mode 100644 index 0000000..d851d90 --- /dev/null +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/driver/AccumuloDualInstanceDriver.java @@ -0,0 +1,621 @@ +/* + * 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.export.accumulo.driver; + +import java.io.File; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.accumulo.core.client.AccumuloException; +import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.Connector; +import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.ZooKeeperInstance; +import org.apache.accumulo.core.client.admin.SecurityOperations; +import org.apache.accumulo.core.client.mock.MockInstance; +import org.apache.accumulo.core.security.Authorizations; +import org.apache.accumulo.core.security.ColumnVisibility; +import org.apache.accumulo.minicluster.MiniAccumuloCluster; +import org.apache.log4j.Logger; +import org.apache.rya.export.accumulo.common.InstanceType; +import org.apache.rya.export.accumulo.util.AccumuloInstanceDriver; + +import mvm.rya.accumulo.AccumuloRdfConfiguration; +import mvm.rya.accumulo.AccumuloRyaDAO; +import mvm.rya.api.domain.RyaStatement; +import mvm.rya.api.persist.RyaDAOException; + +/** + * Handles running a {@link MiniAccumuloCluster} or a {@link MockInstance} for a parent and child instance for testing. + */ +public class AccumuloDualInstanceDriver { + private static final Logger log = Logger.getLogger(AccumuloDualInstanceDriver.class); + + private final InstanceType instanceType; + private final boolean isMock; + private final boolean shouldCreateIndices; + private final boolean isParentReadOnly; + private final boolean isChildReadOnly; + private final boolean doesChildInitiallyExist; + + public static final String PARENT_USER_NAME = "parent_user"; + public static final String PARENT_PASSWORD = "parent_pwd"; + public static final String PARENT_INSTANCE = "parent_instance"; + public static final String PARENT_TABLE_PREFIX = "pt_"; + public static final String PARENT_AUTH = "parent_auth"; + public static final String PARENT_ZOOKEEPERS = "localhost:1111"; + public static final ColumnVisibility PARENT_COLUMN_VISIBILITY = new ColumnVisibility(PARENT_AUTH); + + public static final String CHILD_USER_NAME = "child_user"; + public static final String CHILD_PASSWORD = "child_pwd"; + public static final String CHILD_INSTANCE = "child_instance"; + public static final String CHILD_TABLE_PREFIX = "ct_"; + public static final String CHILD_AUTH = "child_auth"; + public static final String CHILD_ZOOKEEPERS = "localhost:2222"; + public static final ColumnVisibility CHILD_COLUMN_VISIBILITY = new ColumnVisibility(CHILD_AUTH); + + private final AccumuloInstanceDriver parentAccumuloInstanceDriver; + private final AccumuloInstanceDriver childAccumuloInstanceDriver; + + /** + * Creates a new instance of {@link AccumuloDualInstanceDriver}. + * @param instanceType the instanceType of this driver. + * @param shouldCreateIndices {@code true} to create all the indices associated with a Rya deployment. + * {@code false} otherwise. + * @param isParentReadOnly {@code true} if all the tables in the parent instance should have their + * table permissions set to read only. {@code false} if the table permission are set to write. + * @param isChildReadOnly {@code true} if all the tables in the child instance should have their + * table permissions set to read only. {@code false} if the table permission are set to write. + * @param doesChildInitiallyExist {@code true} if all the child instance exists initially. + * {@code false} otherwise. + */ + public AccumuloDualInstanceDriver(final InstanceType instanceType, final boolean shouldCreateIndices, final boolean isParentReadOnly, final boolean isChildReadOnly, final boolean doesChildInitiallyExist) { + this.instanceType = instanceType; + this.isMock = instanceType.isMock(); + this.shouldCreateIndices = shouldCreateIndices; + this.isParentReadOnly = isParentReadOnly; + this.isChildReadOnly = isChildReadOnly; + this.doesChildInitiallyExist = doesChildInitiallyExist; + final String parentUser = isMock ? PARENT_USER_NAME : AccumuloInstanceDriver.ROOT_USER_NAME; + final String childUser = isMock ? CHILD_USER_NAME : AccumuloInstanceDriver.ROOT_USER_NAME; + parentAccumuloInstanceDriver = new AccumuloInstanceDriver("Parent", instanceType, shouldCreateIndices, isParentReadOnly, true, parentUser, PARENT_PASSWORD, PARENT_INSTANCE, PARENT_TABLE_PREFIX, PARENT_AUTH, PARENT_ZOOKEEPERS); + childAccumuloInstanceDriver = new AccumuloInstanceDriver("Child", instanceType, shouldCreateIndices, isChildReadOnly, false, childUser, CHILD_PASSWORD, CHILD_INSTANCE, CHILD_TABLE_PREFIX, CHILD_AUTH, CHILD_ZOOKEEPERS); + } + + /** + * Sets up the parent and child {@link AccumuloInstanceDriver}s. + * @throws Exception + */ + public void setUp() throws Exception { + log.info("Setting up parent and child drivers."); + setUpInstances(); + setUpTables(); + setUpDaos(); + setUpConfigs(); + } + + /** + * Sets up the parent and child instances. + * @throws Exception + */ + public void setUpInstances() throws Exception { + parentAccumuloInstanceDriver.setUpInstance(); + if (doesChildInitiallyExist) { + childAccumuloInstanceDriver.setUpInstance(); + } + } + + /** + * Sets up all the tables and indices for the parent and child instances. + * @throws Exception + */ + public void setUpTables() throws Exception { + parentAccumuloInstanceDriver.setUpTables(); + if (doesChildInitiallyExist) { + childAccumuloInstanceDriver.setUpTables(); + } + } + + /** + * Sets up the {@link AccumuloRyaDAO}s for the parent and child instances. + * @throws Exception + */ + public void setUpDaos() throws Exception { + parentAccumuloInstanceDriver.setUpDao(); + if (doesChildInitiallyExist) { + childAccumuloInstanceDriver.setUpDao(); + } + } + + /** + * Sets up the configuration and prints the arguments for the parent and child instances. + */ + public void setUpConfigs() { + parentAccumuloInstanceDriver.setUpConfig(); + childAccumuloInstanceDriver.setUpConfig(); + } + + /** + * Tears down all the tables and indices for the parent and child instances. + * @throws Exception + */ + public void tearDownTables() throws Exception { + parentAccumuloInstanceDriver.tearDownTables(); + childAccumuloInstanceDriver.tearDownTables(); + } + + /** + * Tears down the {@link AccumuloRyaDAO}s for the parent and child instances. + * @throws Exception + */ + public void tearDownDaos() throws Exception { + parentAccumuloInstanceDriver.tearDownDao(); + childAccumuloInstanceDriver.tearDownDao(); + } + + /** + * Tears down the parent and child instances. + * @throws Exception + */ + public void tearDownInstances() throws Exception { + parentAccumuloInstanceDriver.tearDownInstance(); + childAccumuloInstanceDriver.tearDownInstance(); + } + + /** + * Tears down the {@link AccumuloInstanceDriver} for the parent and child instances. + * @throws Exception + */ + public void tearDown() throws Exception { + try { + //tearDownTables(); + tearDownDaos(); + tearDownInstances(); + } finally { + removeTempDirs(); + } + } + + /** + * Deletes the {@link MiniAccumuloCluster} temporary directories for the parent and child instances. + */ + private void removeTempDirs() { + parentAccumuloInstanceDriver.removeTempDir(); + childAccumuloInstanceDriver.removeTempDir(); + } + + /** + * Adds authorizations to the {@link SecurityOperations} of the parent instance's user. + * @param auths the list of authorizations to add. + * @throws AccumuloException + * @throws AccumuloSecurityException + */ + public void addParentAuths(final String... auths) throws AccumuloException, AccumuloSecurityException { + parentAccumuloInstanceDriver.addAuths(auths); + } + + /** + * Adds authorizations to the {@link SecurityOperations} of the child instance's user. + * @param auths the list of authorizations to add. + * @throws AccumuloException + * @throws AccumuloSecurityException + */ + public void addChildAuths(final String... auths) throws AccumuloException, AccumuloSecurityException { + childAccumuloInstanceDriver.addAuths(auths); + } + + /** + * @return the {@link Authorizations} of the parent instance's user. + * @throws AccumuloException + * @throws AccumuloSecurityException + */ + public Authorizations getParentAuths() throws AccumuloException, AccumuloSecurityException { + return parentAccumuloInstanceDriver.getAuths(); + } + + /** + * @return the {@link Authorizations} of the child instance's user. + * @throws AccumuloException + * @throws AccumuloSecurityException + */ + public Authorizations getChildAuths() throws AccumuloException, AccumuloSecurityException { + return childAccumuloInstanceDriver.getAuths(); + } + + /** + * Adds a {@link Collection} of {@link RyaStatement}s to the parent instance's DAO. + * @param ryaStatements the {@link Collection} of {@link RyaStatement}s. + * @throws RyaDAOException + */ + public void addParentRyaStatements(final Collection<RyaStatement> ryaStatements) throws RyaDAOException { + addRyaStatements(ryaStatements.iterator(), parentAccumuloInstanceDriver.getDao()); + } + + /** + * Adds a {@link Collection} of {@link RyaStatement}s to the child instance's DAO. + * @param ryaStatements the {@link Collection} of {@link RyaStatement}s. + * @throws RyaDAOException + */ + public void addChildRyaStatements(final Collection<RyaStatement> ryaStatements) throws RyaDAOException { + addRyaStatements(ryaStatements.iterator(), childAccumuloInstanceDriver.getDao()); + } + + /** + * Adds {@link RyaStatement}s to the parent instance's DAO from the provided {@link Iterator}. + * @param ryaStatementIterator the {@link RyaStatement} {@link Iterator}. + * @throws RyaDAOException + */ + public void addParentRyaStatements(final Iterator<RyaStatement> ryaStatementIterator) throws RyaDAOException { + addRyaStatements(ryaStatementIterator, parentAccumuloInstanceDriver.getDao()); + } + + /** + * Adds {@link RyaStatement}s to the child instance's DAO from the provided {@link Iterator}. + * @param ryaStatementIterator the {@link RyaStatement} {@link Iterator}. + * @throws RyaDAOException + */ + public void addChildRyaStatements(final Iterator<RyaStatement> ryaStatementIterator) throws RyaDAOException { + addRyaStatements(ryaStatementIterator, childAccumuloInstanceDriver.getDao()); + } + + /** + * Adds a {@link RyaStatement} to the parent instance's DAO. + * @param ryaStatement the {@link RyaStatement}. + * @throws RyaDAOException + */ + public void addParentRyaStatement(final RyaStatement ryaStatement) throws RyaDAOException { + addRyaStatement(ryaStatement, parentAccumuloInstanceDriver.getDao()); + } + + /** + * Adds a {@link RyaStatement} to the child instance's DAO. + * @param ryaStatement the {@link RyaStatement}. + * @throws RyaDAOException + */ + public void addChildRyaStatement(final RyaStatement ryaStatement) throws RyaDAOException { + addRyaStatement(ryaStatement, childAccumuloInstanceDriver.getDao()); + } + + /** + * Adds {@link RyaStatement}s to specified DAO from the provided {@link Iterator}. + * @param ryaStatementIterator the {@link RyaStatement} {@link Iterator}. + * @param dao the {@link AccumuloRyaDAO}. + * @throws RyaDAOException + */ + private static void addRyaStatements(final Iterator<RyaStatement> ryaStatementIterator, final AccumuloRyaDAO dao) throws RyaDAOException { + dao.add(ryaStatementIterator); + } + + /** + * Adds a {@link RyaStatement} to the specified DAO. + * @param ryaStatement the {@link RyaStatement}. + * @throws RyaDAOException + */ + private static void addRyaStatement(final RyaStatement ryaStatement, final AccumuloRyaDAO dao) throws RyaDAOException { + dao.add(ryaStatement); + } + + /** + * @return the parent instance's {@link AccumuloInstanceDriver}. + */ + public AccumuloInstanceDriver getParentAccumuloInstanceDriver() { + return parentAccumuloInstanceDriver; + } + + /** + * @return the child instance's {@link AccumuloInstanceDriver}. + */ + public AccumuloInstanceDriver getChildAccumuloInstanceDriver() { + return childAccumuloInstanceDriver; + } + + /** + * @return the {@link InstanceType} of this driver. + */ + public InstanceType getInstanceType() { + return instanceType; + } + + /** + * @return {@code true} if this is a mock instance. {@code false} if this is a MiniAccumuloCluster instance. + */ + public boolean isMock() { + return isMock; + } + + /** + * @return {@code true} to create all the indices associated with a Rya deployment. + * {@code false} otherwise. + */ + public boolean shouldCreateIndices() { + return shouldCreateIndices; + } + + /** + * @return {@code true} if all the tables in the parent instance should have their + * table permissions set to read only. {@code false} if the table permission are set to write. + */ + public boolean isParentReadOnly() { + return isParentReadOnly; + } + + /** + * @return {@code true} if all the tables in the child instance should have their + * table permissions set to read only. {@code false} if the table permission are set to write. + */ + public boolean isChildReadOnly() { + return isChildReadOnly; + } + + /** + * @return {@code true} if all the child instance exists initially. + * {@code false} otherwise. + */ + public boolean doesChildInitiallyExist() { + return doesChildInitiallyExist; + } + + /** + * @return the user name tied to the parent instance. + */ + public String getParentUser() { + return parentAccumuloInstanceDriver.getUser(); + } + + /** + * @return the user name tied to the child instance. + */ + public String getChildUser() { + return childAccumuloInstanceDriver.getUser(); + } + + /** + * @return the password for the parent instance's user. + */ + public String getParentPassword() { + return parentAccumuloInstanceDriver.getPassword(); + } + + /** + * @return the password for the child instance's user. + */ + public String getChildPassword() { + return childAccumuloInstanceDriver.getPassword(); + } + + /** + * @return the name of the parent instance. + */ + public String getParentInstanceName() { + return parentAccumuloInstanceDriver.getInstanceName(); + } + + /** + * @return the name of the child instance. + */ + public String getChildInstanceName() { + return childAccumuloInstanceDriver.getInstanceName(); + } + + /** + * @return the parent instance's table prefix. + */ + public String getParentTablePrefix() { + return parentAccumuloInstanceDriver.getTablePrefix(); + } + + /** + * @return the child instance's table prefix. + */ + public String getChildTablePrefix() { + return childAccumuloInstanceDriver.getTablePrefix(); + } + + /** + * @return the comma-separated authorization list for the parent instance. + */ + public String getParentAuth() { + return parentAccumuloInstanceDriver.getAuth(); + } + + /** + * @return the comma-separated authorization list for the child instance. + */ + public String getChildAuth() { + return childAccumuloInstanceDriver.getAuth(); + } + + /** + * @return the {@link Connector} to the parent instance. + */ + public Connector getParentConnector() { + return parentAccumuloInstanceDriver.getConnector(); + } + + /** + * @return the {@link Connector} to the child instance. + */ + public Connector getChildConnector() { + return childAccumuloInstanceDriver.getConnector(); + } + + /** + * @return the {@link AccumuloRyaDAO} for the parent instance. + */ + public AccumuloRyaDAO getParentDao() { + return parentAccumuloInstanceDriver.getDao(); + } + + /** + * @return the {@link AccumuloRyaDAO} for the child instance. + */ + public AccumuloRyaDAO getChildDao() { + return childAccumuloInstanceDriver.getDao(); + } + + /** + * @return the {@link SecurityOperations} for the parent instance. + */ + public SecurityOperations getParentSecOps() { + return parentAccumuloInstanceDriver.getSecOps(); + } + + /** + * @return the {@link SecurityOperations} for the child instance. + */ + public SecurityOperations getChildSecOps() { + return childAccumuloInstanceDriver.getSecOps(); + } + + /** + * @return the {@link AccumuloRdfConfiguration} for the parent instance. + */ + public AccumuloRdfConfiguration getParentConfig() { + return parentAccumuloInstanceDriver.getConfig(); + } + + /** + * @return the {@link AccumuloRdfConfiguration} for the child instance. + */ + public AccumuloRdfConfiguration getChildConfig() { + return childAccumuloInstanceDriver.getConfig(); + } + + /** + * @return the {@link MiniAccumuloCluster} for the parent instance or {@code null} + * if this is a {@link MockInstance}. + */ + public MiniAccumuloCluster getParentMiniAccumuloCluster() { + return parentAccumuloInstanceDriver.getMiniAccumuloCluster(); + } + + /** + * @return the {@link MiniAccumuloCluster} for the child instance or {@code null} + * if this is a {@link MockInstance}. + */ + public MiniAccumuloCluster getChildMiniAccumuloCluster() { + return childAccumuloInstanceDriver.getMiniAccumuloCluster(); + } + + /** + * @return the {@link MockInstance} for the parent instance or {@code null} + * if this is a {@link MiniAccumuloCluster}. + */ + public MockInstance getParentMockInstance() { + return parentAccumuloInstanceDriver.getMockInstance(); + } + + /** + * @return the {@link MockInstance} for the child instance or {@code null} + * if this is a {@link MiniAccumuloCluster}. + */ + public MockInstance getChildMockInstance() { + return childAccumuloInstanceDriver.getMockInstance(); + } + + /** + * @return the {@link ZooKeeperInstance} for the parent instance or {@code null} if + * this is a {@link MockInstance}. + */ + public ZooKeeperInstance getParentZooKeeperInstance() { + return parentAccumuloInstanceDriver.getZooKeeperInstance(); + } + + /** + * @return the {@link ZooKeeperInstance} for the child instance or {@code null} if + * this is a {@link MockInstance}. + */ + public ZooKeeperInstance getChildZooKeeperInstance() { + return childAccumuloInstanceDriver.getZooKeeperInstance(); + } + + /** + * @return the parent {@link ZooKeepInstance} or {@link MockInstance}. + */ + public Instance getParentInstance() { + return parentAccumuloInstanceDriver.getInstance(); + } + + /** + * @return the child {@link ZooKeepInstance} or {@link MockInstance}. + */ + public Instance getChildInstance() { + return childAccumuloInstanceDriver.getInstance(); + } + + /** + * @return the comma-separated list of zoo keeper host names for the parent instance. + */ + public String getParentZooKeepers() { + return parentAccumuloInstanceDriver.getZooKeepers(); + } + + /** + * @return the comma-separated list of zoo keeper host names for the child instance. + */ + public String getChildZooKeepers() { + return childAccumuloInstanceDriver.getZooKeepers(); + } + + /** + * @return an unmodifiable map of the configuration keys and values for the parent instance. + */ + public Map<String, String> getParentConfigMap() { + return parentAccumuloInstanceDriver.getConfigMap(); + } + + /** + * @return an unmodifiable map of the configuration keys and values for the child instance. + */ + public Map<String, String> getChildConfigMap() { + return childAccumuloInstanceDriver.getConfigMap(); + } + + /** + * @return an unmodifiable list of the table names and indices for the parent instance. + */ + public List<String> getParentTableList() { + return parentAccumuloInstanceDriver.getTableList(); + } + + /** + * @return an unmodifiable list of the table names and indices for the child instance. + */ + public List<String> getChildTableList() { + return childAccumuloInstanceDriver.getTableList(); + } + + /** + * @return the {@link MiniAccumuloCluster} temporary directory for the parent instance or {@code null} + * if it's a {@link MockInstance}. + */ + public File getParentTempDir() { + return parentAccumuloInstanceDriver.getTempDir(); + } + + /** + * @return the {@link MiniAccumuloCluster} temporary directory for the child instance or {@code null} + * if it's a {@link MockInstance}. + */ + public File getChildTempDir() { + return childAccumuloInstanceDriver.getTempDir(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/parent/AccumuloParentMetadataRepositoryAdapterTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/parent/AccumuloParentMetadataRepositoryAdapterTest.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/parent/AccumuloParentMetadataRepositoryAdapterTest.java new file mode 100644 index 0000000..eca01ee --- /dev/null +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/accumulo/parent/AccumuloParentMetadataRepositoryAdapterTest.java @@ -0,0 +1,67 @@ +package org.apache.rya.export.accumulo.parent; + +import static org.junit.Assert.assertEquals; + +import java.util.Date; + +import org.apache.rya.export.accumulo.common.InstanceType; +import org.apache.rya.export.accumulo.util.AccumuloInstanceDriver; +import org.apache.rya.export.api.parent.MergeParentMetadata; +import org.apache.rya.export.api.parent.ParentMetadataDoesNotExistException; +import org.apache.rya.export.api.parent.ParentMetadataExistsException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests the methods of {@link AccumuloParentMetadataRepository}. + * + */ +public class AccumuloParentMetadataRepositoryAdapterTest { + private final static String TEST_INSTANCE = "test_instance"; + private final static Date TEST_TIMESTAMP = new Date(8675309L); + private final static Date TEST_FILTER_TIMESTAMP = new Date(1234567L); + private final static long TEST_TIME_OFFSET = 123L; + + private static final InstanceType INSTANCE_TYPE = InstanceType.MOCK; + + private static final boolean IS_MOCK = INSTANCE_TYPE.isMock(); + private static final String USER_NAME = IS_MOCK ? "test_user" : AccumuloInstanceDriver.ROOT_USER_NAME; + private static final String PASSWORD = "password"; + private static final String INSTANCE_NAME = "test_instance"; + private static final String AUTHS = "test_auth"; + private static final String RYA_TABLE_PREFIX = "test_"; + private static final String ZOOKEEPERS = "localhost"; + + private static AccumuloInstanceDriver accumuloInstanceDriver; + private static AccumuloParentMetadataRepository accumuloParentMetadataRepository; + + @BeforeClass + public static void setUp() throws Exception { + accumuloInstanceDriver = new AccumuloInstanceDriver("Test Repository", INSTANCE_TYPE, false, false, true, USER_NAME, PASSWORD, INSTANCE_NAME, RYA_TABLE_PREFIX, AUTHS, ZOOKEEPERS); + accumuloInstanceDriver.setUp(); + + accumuloParentMetadataRepository = new AccumuloParentMetadataRepository(accumuloInstanceDriver.getDao()); + } + + @AfterClass + public static void tearDownPerClass() throws Exception { + accumuloInstanceDriver.tearDown(); + } + + @Test + public void setAndGetTest() throws ParentMetadataExistsException, ParentMetadataDoesNotExistException { + final MergeParentMetadata mergeParentMetadata = new MergeParentMetadata.Builder() + .setRyaInstanceName(TEST_INSTANCE) + .setTimestamp(TEST_TIMESTAMP) + .setFilterTimestmap(TEST_FILTER_TIMESTAMP) + .setParentTimeOffset(TEST_TIME_OFFSET) + .build(); + + accumuloParentMetadataRepository.set(mergeParentMetadata); + + final MergeParentMetadata actual = accumuloParentMetadataRepository.get(); + assertEquals(mergeParentMetadata, actual); + } +} + http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapterTest.java ---------------------------------------------------------------------- diff --git a/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapterTest.java b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapterTest.java new file mode 100644 index 0000000..ad322a3 --- /dev/null +++ b/extras/rya.export/export.accumulo/src/test/java/org/apache/rya/export/api/conf/AccumuloConfigurationAdapterTest.java @@ -0,0 +1,145 @@ +/* + * 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.export.api.conf; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Date; + +import org.apache.rya.export.DBType; +import org.apache.rya.export.JAXBAccumuloMergeConfiguration; +import org.apache.rya.export.MergePolicy; +import org.apache.rya.export.accumulo.common.InstanceType; +import org.apache.rya.export.accumulo.conf.AccumuloExportConstants; +import org.apache.rya.export.accumulo.driver.AccumuloDualInstanceDriver; +import org.apache.rya.export.accumulo.util.AccumuloInstanceDriver; +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests the methods of {@link AccumuloConfigurationAdapter}. + */ +public class AccumuloConfigurationAdapterTest { + private static final InstanceType INSTANCE_TYPE = InstanceType.MOCK; + + private static final boolean IS_MOCK = INSTANCE_TYPE.isMock(); + private static final boolean USE_TIME_SYNC = false; + + private static final String PARENT_HOST_NAME = "localhost:1234"; + private static final int PARENT_PORT = 1111; + private static final String PARENT_USER_NAME = IS_MOCK ? "parent_user" : AccumuloInstanceDriver.ROOT_USER_NAME; + private static final String PARENT_PASSWORD = AccumuloDualInstanceDriver.PARENT_PASSWORD; + private static final String PARENT_INSTANCE = AccumuloDualInstanceDriver.PARENT_INSTANCE; + private static final String PARENT_TABLE_PREFIX = AccumuloDualInstanceDriver.PARENT_TABLE_PREFIX; + private static final String PARENT_AUTH = AccumuloDualInstanceDriver.PARENT_AUTH; + private static final String PARENT_TOMCAT_URL = "http://localhost:8080"; + private static final String PARENT_ZOOKEEPERS = "http://rya-example-box:9090"; + + private static final String CHILD_HOST_NAME = "localhost:4321"; + private static final int CHILD_PORT = 2222; + private static final String CHILD_USER_NAME = IS_MOCK ? "child_user" : AccumuloInstanceDriver.ROOT_USER_NAME; + private static final String CHILD_PASSWORD = AccumuloDualInstanceDriver.CHILD_PASSWORD; + private static final String CHILD_INSTANCE = AccumuloDualInstanceDriver.CHILD_INSTANCE; + private static final String CHILD_TABLE_PREFIX = AccumuloDualInstanceDriver.CHILD_TABLE_PREFIX; + private static final String CHILD_AUTH = AccumuloDualInstanceDriver.CHILD_AUTH; + private static final String CHILD_TOMCAT_URL = "http://localhost:8080"; + private static final String CHILD_ZOOKEEPERS = "http://localhost:9999"; + + + private static final String TOOL_START_TIME = AccumuloExportConstants.convertDateToStartTimeString(new Date()); + private static final String TIME_SERVER = "time.nist.gov"; + + @Test + public void testCreateConfig() throws MergeConfigurationException { + final JAXBAccumuloMergeConfiguration jConfig = mock(JAXBAccumuloMergeConfiguration.class); + // Parent Properties + when(jConfig.getParentHostname()).thenReturn(PARENT_HOST_NAME); + when(jConfig.getParentPort()).thenReturn(PARENT_PORT); + when(jConfig.getParentRyaInstanceName()).thenReturn(PARENT_INSTANCE); + when(jConfig.getParentUsername()).thenReturn(PARENT_USER_NAME); + when(jConfig.getParentPassword()).thenReturn(PARENT_PASSWORD); + when(jConfig.getParentTablePrefix()).thenReturn(PARENT_TABLE_PREFIX); + when(jConfig.getParentDBType()).thenReturn(DBType.ACCUMULO); + when(jConfig.getParentTomcatUrl()).thenReturn(PARENT_TOMCAT_URL); + // Parent Accumulo Properties + when(jConfig.getParentInstanceType()).thenReturn(INSTANCE_TYPE.toString()); + when(jConfig.getParentAuths()).thenReturn(PARENT_AUTH); + when(jConfig.getParentZookeepers()).thenReturn(PARENT_ZOOKEEPERS); + + // Child Properties + when(jConfig.getChildHostname()).thenReturn(CHILD_HOST_NAME); + when(jConfig.getChildPort()).thenReturn(CHILD_PORT); + when(jConfig.getChildRyaInstanceName()).thenReturn(CHILD_INSTANCE); + when(jConfig.getChildUsername()).thenReturn(CHILD_USER_NAME); + when(jConfig.getChildPassword()).thenReturn(CHILD_PASSWORD); + when(jConfig.getChildTablePrefix()).thenReturn(CHILD_TABLE_PREFIX); + when(jConfig.getChildDBType()).thenReturn(DBType.ACCUMULO); + when(jConfig.getChildTomcatUrl()).thenReturn(CHILD_TOMCAT_URL); + // Child Accumulo Properties + when(jConfig.getChildInstanceType()).thenReturn(INSTANCE_TYPE.toString()); + when(jConfig.getChildAuths()).thenReturn(CHILD_AUTH); + when(jConfig.getChildZookeepers()).thenReturn(CHILD_ZOOKEEPERS); + // Other Properties + when(jConfig.getMergePolicy()).thenReturn(MergePolicy.TIMESTAMP); + when(jConfig.getNtpServerHost()).thenReturn(TIME_SERVER); + when(jConfig.isUseNtpServer()).thenReturn(USE_TIME_SYNC); + when(jConfig.getToolStartTime()).thenReturn(TOOL_START_TIME); + + + final AccumuloMergeConfiguration accumuloMergeConfiguration = AccumuloConfigurationAdapter.createConfig(jConfig); + + Assert.assertNotNull(accumuloMergeConfiguration); + Assert.assertEquals(AccumuloMergeConfiguration.class, accumuloMergeConfiguration.getClass()); + + // Parent Properties + Assert.assertEquals(PARENT_HOST_NAME, accumuloMergeConfiguration.getParentHostname()); + Assert.assertEquals(PARENT_USER_NAME, accumuloMergeConfiguration.getParentUsername()); + Assert.assertEquals(PARENT_PASSWORD, accumuloMergeConfiguration.getParentPassword()); + Assert.assertEquals(PARENT_INSTANCE, accumuloMergeConfiguration.getParentRyaInstanceName()); + Assert.assertEquals(PARENT_TABLE_PREFIX, accumuloMergeConfiguration.getParentTablePrefix()); + Assert.assertEquals(PARENT_TOMCAT_URL, accumuloMergeConfiguration.getParentTomcatUrl()); + Assert.assertEquals(DBType.ACCUMULO, accumuloMergeConfiguration.getParentDBType()); + Assert.assertEquals(PARENT_PORT, accumuloMergeConfiguration.getParentPort()); + // Parent Accumulo Properties + Assert.assertEquals(PARENT_ZOOKEEPERS, accumuloMergeConfiguration.getParentZookeepers()); + Assert.assertEquals(PARENT_AUTH, accumuloMergeConfiguration.getParentAuths()); + Assert.assertEquals(InstanceType.MOCK, accumuloMergeConfiguration.getParentInstanceType()); + + // Child Properties + Assert.assertEquals(CHILD_HOST_NAME, accumuloMergeConfiguration.getChildHostname()); + Assert.assertEquals(CHILD_USER_NAME, accumuloMergeConfiguration.getChildUsername()); + Assert.assertEquals(CHILD_PASSWORD, accumuloMergeConfiguration.getChildPassword()); + Assert.assertEquals(CHILD_INSTANCE, accumuloMergeConfiguration.getChildRyaInstanceName()); + Assert.assertEquals(CHILD_TABLE_PREFIX, accumuloMergeConfiguration.getChildTablePrefix()); + Assert.assertEquals(CHILD_TOMCAT_URL, accumuloMergeConfiguration.getChildTomcatUrl()); + Assert.assertEquals(DBType.ACCUMULO, accumuloMergeConfiguration.getChildDBType()); + Assert.assertEquals(CHILD_PORT, accumuloMergeConfiguration.getChildPort()); + // Child Properties + Assert.assertEquals(CHILD_ZOOKEEPERS, accumuloMergeConfiguration.getChildZookeepers()); + Assert.assertEquals(CHILD_AUTH, accumuloMergeConfiguration.getChildAuths()); + Assert.assertEquals(InstanceType.MOCK, accumuloMergeConfiguration.getChildInstanceType()); + + // Other Properties + Assert.assertEquals(MergePolicy.TIMESTAMP, accumuloMergeConfiguration.getMergePolicy()); + Assert.assertEquals(Boolean.FALSE, accumuloMergeConfiguration.getUseNtpServer()); + Assert.assertEquals(TIME_SERVER, accumuloMergeConfiguration.getNtpServerHost()); + Assert.assertEquals(TOOL_START_TIME, accumuloMergeConfiguration.getToolStartTime()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/f2b046f3/extras/rya.export/pom.xml ---------------------------------------------------------------------- diff --git a/extras/rya.export/pom.xml b/extras/rya.export/pom.xml index b2fd1d1..a23de7f 100644 --- a/extras/rya.export/pom.xml +++ b/extras/rya.export/pom.xml @@ -37,6 +37,7 @@ under the License. <packaging>pom</packaging> <modules> + <module>export.accumulo</module> <module>export.api</module> <module>export.mongo</module> </modules>
