From 1754cb76e065f83d76550a55af674bff34a490cc Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 26 Mar 2014 06:01:32 +0000 Subject: [PATCH] all tests passed with cassandra implementation: does not mean everyhting is really working but a good step :-) git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581699 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractMetadataRepositoryTest.java | 12 +++--- .../CassandraMetadataRepository.java | 38 +++++++++++++++---- .../model/ProjectVersionMetadataModel.java | 22 ++++++----- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index 49738d220..f419e1fb0 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -837,10 +837,10 @@ public abstract class AbstractMetadataRepositoryTest repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 ); - List versions = new ArrayList( - repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ); - Collections.sort( versions ); - assertEquals( Arrays.asList( version1, version2 ), versions ); + Collection versions = + repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); + + assertThat( versions ).isNotNull().isNotEmpty().contains( version1, version2 ); } @Test @@ -1235,8 +1235,8 @@ public abstract class AbstractMetadataRepositoryTest repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); - assertEquals( Collections.singletonList( artifact ), new ArrayList( - repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); + assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, + TEST_PROJECT_VERSION ) ).containsExactly( artifact ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact ); diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index f7525e61d..db913362b 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -853,8 +853,13 @@ public class CassandraMetadataRepository projectVersionMetadataModel.setLicenses( versionMetadata.getLicenses() ); // we don't test of repository and namespace really exist ! - String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace( - namespaceId ).withProjectId( projectId ).withId( versionMetadata.getId() ).build(); + String key = new ProjectVersionMetadataModel.KeyBuilder() // + .withRepository( repositoryId ) // + .withNamespace( namespaceId ) // + .withProjectId( projectId ) // + .withProjectVersion( versionMetadata.getVersion() ) // + .withVersion( versionMetadata.getId() ) // + .build(); // FIXME nested objects to store!!! if ( creation ) @@ -1435,10 +1440,25 @@ public class CassandraMetadataRepository .withRepository( repositoryId ) // .withNamespace( namespace ) // .withProjectId( projectId ) // - .withId( artifactMeta.getId() ) // + .withProjectVersion( projectVersion ) // + .withVersion( artifactMeta.getId() ) // .build(); - exists = this.projectVersionMetadataModelTemplate.isColumnsExist( key ); + Keyspace keyspace = cassandraArchivaManager.getKeyspace(); + StringSerializer ss = StringSerializer.get(); + + QueryResult> result = HFactory // + .createRangeSlicesQuery( keyspace, ss, ss, ss ) // + .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // + .setColumnNames( "version" ) // + .addEqualsExpression( "repositoryName", repositoryId ) // + .addEqualsExpression( "namespaceId", namespaceId ) // + .addEqualsExpression( "projectId", projectId ) // + .addEqualsExpression( "projectVersion", projectVersion ) // + .addEqualsExpression( "version", artifactMeta.getVersion() ) // + .execute(); + + exists = result.get().getCount() > 0; if ( !exists ) { @@ -1892,9 +1912,13 @@ public class CassandraMetadataRepository this.artifactMetadataTemplate.deleteRow( key ); - key = - new ProjectVersionMetadataModel.KeyBuilder().withId( version ).withRepository( repositoryId ).withNamespace( - namespace ).withProjectId( project ).build(); + key = new ProjectVersionMetadataModel.KeyBuilder() // + .withRepository( repositoryId ) // + .withNamespace( namespace ) // + .withProjectId( project ) // + .withProjectVersion( version ) // + .withVersion( id ) // + .build(); this.projectVersionMetadataModelTemplate.deleteRow( key ); } diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java index d441d19bd..faacbc14f 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java @@ -248,7 +248,6 @@ public class ProjectVersionMetadataModel } - public static class KeyBuilder { @@ -258,11 +257,13 @@ public class ProjectVersionMetadataModel private String projectId; - private String id; + private String projectVersion; + + private String version; public KeyBuilder() { - + // no op } public KeyBuilder withNamespace( Namespace namespace ) @@ -284,28 +285,29 @@ public class ProjectVersionMetadataModel return this; } - public KeyBuilder withRepository( Repository repository ) + public KeyBuilder withProjectId( String projectId ) { - this.repositoryName = repository.getName(); + this.projectId = projectId; return this; } - public KeyBuilder withProjectId( String projectId ) + public KeyBuilder withProjectVersion( String projectVersion ) { - this.projectId = projectId; + this.projectVersion = projectVersion; return this; } - public KeyBuilder withId( String id ) + public KeyBuilder withVersion( String version ) { - this.id = id; + this.version = version; return this; } public String build() { // FIXME add some controls - return CassandraUtils.generateKey( this.repositoryName, this.namespace, this.projectId, this.id ); + return CassandraUtils.generateKey( this.repositoryName, this.namespace, this.projectId, this.projectVersion, + this.version ); } } } -- 2.39.5