From 173745690325d46dbdd75a60f8b0ad6e92725481 Mon Sep 17 00:00:00 2001 From: Rui Han Date: Fri, 1 Nov 2019 11:37:40 +0800 Subject: [PATCH] Fix the remaining ftests which were failed due to the change to file check --- .../core/AbstractIndyFunctionalTest.java | 4 +++- ...GroupHttpHeadersFromSameRepoAsPomTest.java | 21 ++++++------------- .../GroupMetadataMergeInfoGenTest.java | 9 ++++---- ...thoritativeIndexedContentInHostedTest.java | 12 +++++------ 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/ftests/common/src/main/java/org/commonjava/indy/ftest/core/AbstractIndyFunctionalTest.java b/ftests/common/src/main/java/org/commonjava/indy/ftest/core/AbstractIndyFunctionalTest.java index 6569669d90..c852f3bd09 100644 --- a/ftests/common/src/main/java/org/commonjava/indy/ftest/core/AbstractIndyFunctionalTest.java +++ b/ftests/common/src/main/java/org/commonjava/indy/ftest/core/AbstractIndyFunctionalTest.java @@ -86,6 +86,8 @@ public abstract class AbstractIndyFunctionalTest protected File storageDir; + protected CacheProvider cacheProvider; + @SuppressWarnings( "resource" ) @Before public void start() @@ -120,6 +122,7 @@ public void run() } client = createIndyClient(); + cacheProvider = CDI.current().select( CacheProvider.class ).get(); } catch ( Throwable t ) { @@ -196,7 +199,6 @@ public void stop() // TODO: this is a hack due to the "shutdown action not executed" issue. Once propulsor lifecycle shutdown is applied, this can be replaced. private void closeCacheProvider() { - CacheProvider cacheProvider = CDI.current().select( CacheProvider.class ).get(); if ( cacheProvider != null ) { cacheProvider.asAdminView().close(); diff --git a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupHttpHeadersFromSameRepoAsPomTest.java b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupHttpHeadersFromSameRepoAsPomTest.java index 5893b54b14..07e498a7f1 100644 --- a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupHttpHeadersFromSameRepoAsPomTest.java +++ b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupHttpHeadersFromSameRepoAsPomTest.java @@ -25,6 +25,8 @@ import org.commonjava.indy.model.core.Group; import org.commonjava.indy.model.core.RemoteRepository; import org.commonjava.indy.model.util.HttpUtils; +import org.commonjava.indy.util.LocationUtils; +import org.commonjava.maven.galley.model.ConcreteResource; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; @@ -83,7 +85,7 @@ public class GroupHttpHeadersFromSameRepoAsPomTest private static final String CONTENT_2 = "This is content #2. Some more content, here."; - private static final String PATH = "/path/to/test.txt"; + private static final String PATH = "path/to/test.txt"; private RemoteRepository repoX; @@ -120,20 +122,9 @@ public void run() assertContent( repoX, PATH, CONTENT_1 ); assertContent( repoY, PATH, CONTENT_2 ); -// repoX.setDisabled( true ); -// client.stores().update( repoX, "disabling" ); - - File remoteXFile = Paths.get( fixture.getBootOptions().getHomeDir(), "var/lib/indy/storage", MAVEN_PKG_KEY, - remote.singularEndpointName() + "-X", PATH ).toFile(); - - waitForEventPropagation(); - - Logger logger = LoggerFactory.getLogger( getClass() ); - logger.debug( "Deleting main file: {} (leaving associated http-metadata.json file in place)", remoteXFile ); - - assertThat( "Failed to delete: " + remoteXFile, remoteXFile.delete(), equalTo( true ) ); - - waitForEventPropagation(); + ConcreteResource res = new ConcreteResource( LocationUtils.toLocation( repoX ), PATH ); + cacheProvider.delete( res ); + logger.debug( "Deleting main file: {} (leaving associated http-metadata.json file in place)", res ); assertContentLength( groupA, PATH, content2.length ); assertContentLength( repoX, PATH, CONTENT_1.getBytes().length ); diff --git a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupMetadataMergeInfoGenTest.java b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupMetadataMergeInfoGenTest.java index a7324e738f..2b4ccb2142 100644 --- a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupMetadataMergeInfoGenTest.java +++ b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/GroupMetadataMergeInfoGenTest.java @@ -25,6 +25,7 @@ import org.commonjava.indy.model.core.StoreType; import org.commonjava.indy.util.LocationUtils; +import org.commonjava.maven.galley.model.ConcreteResource; import org.junit.Test; import java.io.ByteArrayInputStream; @@ -196,12 +197,10 @@ private Group updateAndRetrieve( final Group g, final String changeLog, final St private void assertInfoContent( final ArtifactStore store, final String path, final String expectedContent ) throws Exception { - final File infoFile = getPhysicalStorageFile( LocationUtils.toLocation( store ), path + GroupMergeHelper.MERGEINFO_SUFFIX ); - assertThat( "info file doesn't exist", infoFile.exists(), equalTo( true ) ); - - try (final InputStream stream = new FileInputStream( infoFile )) + ConcreteResource res = new ConcreteResource( LocationUtils.toLocation( store ), + path + GroupMergeHelper.MERGEINFO_SUFFIX ); + try (final InputStream stream = cacheProvider.openInputStream( res ) ) { - System.out.println( stream ); assertThat( IOUtils.toString( stream ), equalTo( expectedContent ) ); } } diff --git a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/contentindex/AuthoritativeIndexedContentInHostedTest.java b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/contentindex/AuthoritativeIndexedContentInHostedTest.java index c3a08d459a..889507a39c 100644 --- a/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/contentindex/AuthoritativeIndexedContentInHostedTest.java +++ b/ftests/core/src/main/java/org/commonjava/indy/ftest/core/content/contentindex/AuthoritativeIndexedContentInHostedTest.java @@ -20,6 +20,8 @@ import org.commonjava.indy.ftest.core.category.EventDependent; import org.commonjava.indy.model.core.HostedRepository; import org.commonjava.indy.test.fixture.core.CoreServerFixture; +import org.commonjava.indy.util.LocationUtils; +import org.commonjava.maven.galley.model.ConcreteResource; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -27,6 +29,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -91,13 +94,8 @@ public void bypassNotIndexedContentWithAuthoritativeIndex() client.content() .store( repo.getKey(), CACHED_AFACT_PATH, new ByteArrayInputStream( CACHED_CONTENT.getBytes() ) ); - final Path nonCachedFile = - Paths.get( fixture.getBootOptions().getHomeDir(), "var/lib/indy/storage", MAVEN_PKG_KEY, - hosted.singularEndpointName() + "-" + repoName, NON_CACHED_AFACT_PATH ); - Files.createDirectories( nonCachedFile.getParent() ); - Files.createFile( nonCachedFile ); - - try (FileOutputStream stream = new FileOutputStream( nonCachedFile.toFile() )) + ConcreteResource res = new ConcreteResource( LocationUtils.toLocation( repo ), NON_CACHED_AFACT_PATH ); + try (OutputStream stream = cacheProvider.openOutputStream( res )) { stream.write( NON_CACHED_CONTENT.getBytes() ); }