]> source.dussan.org Git - archiva.git/commitdiff
all tests passed with cassandra implementation: does not mean everyhting is really...
authorOlivier Lamy <olamy@apache.org>
Wed, 26 Mar 2014 06:01:32 +0000 (06:01 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 26 Mar 2014 06:01:32 +0000 (06:01 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581699 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java
archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/model/ProjectVersionMetadataModel.java

index 49738d220919c7df5c844c72fe459244884101b3..f419e1fb085e5af3ae21145bd40504976354a762 100644 (file)
@@ -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<String> versions = new ArrayList<String>(
-            repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) );
-        Collections.sort( versions );
-        assertEquals( Arrays.asList( version1, version2 ), versions );
+        Collection<String> 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<ArtifactMetadata>(
-            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 );
 
index f7525e61d02dad1b6941ba0401870388ecf44760..db913362bf0d78194cca34a38a6c6c29c0ca0408 100644 (file)
@@ -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<OrderedRows<String, String, String>> 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 );
     }
index d441d19bd687de656df92062d478101f3ccf821e..faacbc14fe0307c1358c2e69b9f58795ad92d650 100644 (file)
@@ -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 );
         }
     }
 }