]> source.dussan.org Git - archiva.git/commitdiff
Trying to speed up table truncate
authorMartin Stockhammer <martin_s@apache.org>
Sun, 29 Aug 2021 11:57:22 +0000 (13:57 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 29 Aug 2021 11:57:22 +0000 (13:57 +0200)
archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/pom.xml
archiva-modules/metadata/metadata-store-provider/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java

index e0f592a7af8c5c96b7300373e7a1f01bfa8bf1ac..477482870f1388bf22a6e092276ae91b695736c7 100644 (file)
               <addTestClasspath>false</addTestClasspath>
               <startWaitSeconds>500</startWaitSeconds>
               <startNativeTransport>true</startNativeTransport>
-              <logLevel>DEBUG</logLevel>
+              <logLevel>INFO</logLevel>
               <loadAfterFirstStart>false</loadAfterFirstStart>
               <yaml>
                 broadcast_rpc_address: 127.0.0.1
               <systemPropertyVariables>
                 <java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
               </systemPropertyVariables>
+
             </configuration>
           </execution>
           <execution>
index 4ab388149369c656796acc08ab446d82e3352bf8..71636efb422637dc29a6cdcb378bf6153d632512 100644 (file)
@@ -44,7 +44,10 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
 
 import static com.datastax.oss.driver.api.querybuilder.QueryBuilder.truncate;
 import static com.datastax.oss.driver.api.querybuilder.SchemaBuilder.dropTable;
@@ -72,7 +75,7 @@ public class CassandraMetadataRepositoryTest
 
     long cTime;
     int testNum = 0;
-    AtomicBoolean clearedTables = new AtomicBoolean( false );
+    final AtomicBoolean clearedTables = new AtomicBoolean( false );
 
 
     @Override
@@ -121,8 +124,7 @@ public class CassandraMetadataRepositoryTest
 
         if (!clearedTables.get())
         {
-            clearReposAndNamespace( cassandraArchivaManager );
-            clearedTables.set( true );
+            clearReposAndNamespace( cassandraArchivaManager, clearedTables );
         }
         System.err.println( "Finished setting up - "+testInfo.getDisplayName() + " - " + (System.currentTimeMillis( ) - cTime) +"ms");
     }
@@ -164,13 +166,12 @@ public class CassandraMetadataRepositoryTest
         throws Exception
     {
         System.err.println( "Shutting down - " + (testNum-1) + " - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms");
-        clearReposAndNamespace( cassandraArchivaManager );
-        clearedTables.set( true );
+        clearReposAndNamespace( cassandraArchivaManager, clearedTables );
         super.tearDown();
         System.err.println( "Shutting down finished - " + testInfo.getDisplayName( ) + " - " + ( System.currentTimeMillis( ) - cTime ) +"ms");
     }
 
-    static void clearReposAndNamespace( CassandraArchivaManager cassandraArchivaManager )
+    static void clearReposAndNamespace( final CassandraArchivaManager cassandraArchivaManager, final AtomicBoolean clearedFlag )
         throws Exception
     {
         if (cassandraArchivaManager!=null)
@@ -188,15 +189,21 @@ public class CassandraMetadataRepositoryTest
                     cassandraArchivaManager.getLicenseFamilyName( ),
                     cassandraArchivaManager.getDependencyFamilyName( )
                 );
-                for ( String table : tables )
-                {
-                    session.execute( truncate( table ).build( ) );
-                }
-
+                CompletableFuture.allOf( tables.stream( ).map( table -> session.executeAsync( truncate( table ).build( ) ) )
+                        .map( CompletionStage::toCompletableFuture ).collect( Collectors.toList( ) ).toArray( new CompletableFuture[0] ) )
+                    .thenAccept( ( c ) -> {
+                        if ( clearedFlag != null ) clearedFlag.set( true );
+                    } ).get( )
+                ;
             }
         } else {
             System.err.println( "cassandraArchivaManager is null" );
         }
     }
 
+    static void clearReposAndNamespace( final CassandraArchivaManager cassandraArchivaManager)
+        throws Exception {
+        clearReposAndNamespace( cassandraArchivaManager, null );
+    }
+
 }