Repository: zest-java Updated Branches: refs/heads/develop 31c28431c -> 7ac533885
reindexer: rework test so it is more reliable Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/85f2eb58 Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/85f2eb58 Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/85f2eb58 Branch: refs/heads/develop Commit: 85f2eb5815cc3eb3adb6079740a5dd97d1226dd5 Parents: 31c2843 Author: Paul Merlin <[email protected]> Authored: Fri Dec 2 17:56:27 2016 +0100 Committer: Paul Merlin <[email protected]> Committed: Fri Dec 2 17:56:27 2016 +0100 ---------------------------------------------------------------------- .../zest/index/reindexer/ReindexerTest.java | 87 +++++++------------- .../jdbm/JdbmEntityStoreService.properties | 21 ----- .../rdf/repository/rdf-indexing.properties | 21 ----- 3 files changed, 29 insertions(+), 100 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zest-java/blob/85f2eb58/extensions/reindexer/src/test/java/org/apache/zest/index/reindexer/ReindexerTest.java ---------------------------------------------------------------------- diff --git a/extensions/reindexer/src/test/java/org/apache/zest/index/reindexer/ReindexerTest.java b/extensions/reindexer/src/test/java/org/apache/zest/index/reindexer/ReindexerTest.java index 9feead5..1786c83 100644 --- a/extensions/reindexer/src/test/java/org/apache/zest/index/reindexer/ReindexerTest.java +++ b/extensions/reindexer/src/test/java/org/apache/zest/index/reindexer/ReindexerTest.java @@ -19,11 +19,11 @@ */ package org.apache.zest.index.reindexer; -import info.aduna.io.FileUtil; import java.io.File; -import org.apache.tools.ant.util.FileUtils; -import org.junit.AfterClass; -import org.junit.Test; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.stream.Stream; import org.apache.zest.api.common.Visibility; import org.apache.zest.api.entity.EntityBuilder; import org.apache.zest.api.entity.EntityComposite; @@ -40,21 +40,26 @@ import org.apache.zest.index.rdf.assembly.RdfNativeSesameStoreAssembler; import org.apache.zest.library.rdf.repository.NativeConfiguration; import org.apache.zest.test.AbstractZestTest; import org.apache.zest.test.EntityTestAssembler; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; import static org.apache.zest.api.query.QueryExpressions.eq; import static org.apache.zest.api.query.QueryExpressions.templateFor; +import static org.junit.Assert.assertEquals; -@SuppressWarnings( "PublicInnerClass" ) public class ReindexerTest - extends AbstractZestTest + extends AbstractZestTest { + private static final String ENTITIES_DIR = "zest-entities"; + private static final String INDEX_DIR = "zest-index"; + + @Rule + public final TemporaryFolder tmpDir = new TemporaryFolder(); - @SuppressWarnings( "unchecked" ) + @Override public void assemble( ModuleAssembly module ) - throws AssemblyException + throws AssemblyException { // JDBM EntityStore new JdbmEntityStoreAssembler().assemble( module ); @@ -70,30 +75,29 @@ public class ReindexerTest // Configuration ModuleAssembly config = module.layer().module( "config" ); new EntityTestAssembler().assemble( config ); - config.entities( JdbmConfiguration.class, NativeConfiguration.class, ReindexerConfiguration.class ).visibleIn( Visibility.layer ); + config.entities( JdbmConfiguration.class, NativeConfiguration.class, ReindexerConfiguration.class ) + .visibleIn( Visibility.layer ); + config.forMixin( JdbmConfiguration.class ).declareDefaults() + .file().set( new File( tmpDir.getRoot(), ENTITIES_DIR ).getAbsolutePath() ); + config.forMixin( NativeConfiguration.class ).declareDefaults() + .dataDirectory().set( new File( tmpDir.getRoot(), INDEX_DIR ).getAbsolutePath() ); // Test entity module.entities( MyEntity.class ); - } private static final String TEST_NAME = "foo"; - public static interface MyEntity - extends EntityComposite + public interface MyEntity extends EntityComposite { Property<String> name(); - } @Test public void createDataWipeIndexReindexAndAssertData() - throws UnitOfWorkCompletionException + throws UnitOfWorkCompletionException, IOException { - File rdfDir = new File( System.getProperty( "user.dir" ), "build/testdata/zest-index" ).getAbsoluteFile(); - rdfDir.mkdirs(); - assertThat( rdfDir.exists(), is(true) ); // ----> Create data and wipe index @@ -106,8 +110,11 @@ public class ReindexerTest uow.complete(); - deleteIndexData(); // Wipe the index data on disk - rdfDir.mkdirs(); + // Wipe the index data on disk + try( Stream<Path> files = Files.walk( new File( tmpDir.getRoot(), INDEX_DIR ).getAbsoluteFile().toPath() ) ) + { + files.map( Path::toFile ).forEach( File::delete ); + } // ----> Reindex and assert data @@ -128,40 +135,4 @@ public class ReindexerTest uow.complete(); } - - @AfterClass - @SuppressWarnings( "AssignmentReplaceableWithOperatorAssignment" ) - public static void afterClass() - throws Exception - { - boolean success = true; - success = deleteEntitiesData(); - success = success & deleteIndexData(); - if ( !success ) { - throw new Exception( "Could not delete test data" ); - } - - } - - private static boolean deleteEntitiesData() - { - boolean success = true; - File esDir = new File( System.getProperty( "user.dir" ), "build/testdata/zest-entities" ).getAbsoluteFile(); - if ( esDir.exists() ) { - success = FileUtil.deltree( esDir ); - } - return success; - } - - private static boolean deleteIndexData() - { - boolean success = true; - File rdfDir = new File( System.getProperty( "user.dir" ), "build/testdata/zest-index" ).getAbsoluteFile(); - if ( rdfDir.exists() ) { - FileUtils.delete( rdfDir ); - success = FileUtil.deltree( rdfDir ); - } - return success; - } - } http://git-wip-us.apache.org/repos/asf/zest-java/blob/85f2eb58/extensions/reindexer/src/test/resources/org/apache/zest/entitystore/jdbm/JdbmEntityStoreService.properties ---------------------------------------------------------------------- diff --git a/extensions/reindexer/src/test/resources/org/apache/zest/entitystore/jdbm/JdbmEntityStoreService.properties b/extensions/reindexer/src/test/resources/org/apache/zest/entitystore/jdbm/JdbmEntityStoreService.properties deleted file mode 100644 index b87070c..0000000 --- a/extensions/reindexer/src/test/resources/org/apache/zest/entitystore/jdbm/JdbmEntityStoreService.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# -# -# - -file=build/testdata/zest-entities/zest-entities \ No newline at end of file http://git-wip-us.apache.org/repos/asf/zest-java/blob/85f2eb58/extensions/reindexer/src/test/resources/org/apache/zest/library/rdf/repository/rdf-indexing.properties ---------------------------------------------------------------------- diff --git a/extensions/reindexer/src/test/resources/org/apache/zest/library/rdf/repository/rdf-indexing.properties b/extensions/reindexer/src/test/resources/org/apache/zest/library/rdf/repository/rdf-indexing.properties deleted file mode 100644 index 07681f9..0000000 --- a/extensions/reindexer/src/test/resources/org/apache/zest/library/rdf/repository/rdf-indexing.properties +++ /dev/null @@ -1,21 +0,0 @@ -# -# 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. -# -# -# - -dataDirectory=build/testdata/zest-index \ No newline at end of file
