Elffuss BraidHub

kikocis/java-driver public

Optimize clearSimpleKeyspace by dropping tables if more than 10.
Changesetc0a7681387c1814cd19ab91c03ead5ac125dd609c106eaf883ca843b39569f4f
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-11-04 08:30 -06:00
Committerolim7t <omichallat+github@gmail.com> · 2015-11-05 18:37 +01:00
Parentsbaf47da1c074

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +15 −4
@@ -506,19 +506,30 @@
506506
507507 private void clearSimpleKeyspace() {
508508 if(keyspace != null) {
509- // Temporarily extend read timeout to 1 minute to accommodate keyspaces with many tables.
510- // This should be more than enough although some tests create many tables, so dropping a keyspace
511- // could take as long as 12 seconds on restricted hardware.
509+ logger.debug("Removing keyspace {}.", keyspace);
510+ // Temporarily extend read timeout to 1 minute to accommodate dropping keyspaces and
511+ // tables being slow, particularly in a CI environment.
512512 int currentTimeout = cluster.getConfiguration().getSocketOptions().getReadTimeoutMillis();
513513 cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(60000);
514514 try {
515+ KeyspaceMetadata ksm = cluster.getMetadata().getKeyspace(keyspace);
516+ if (ksm != null) {
517+ // drop each table individually as this seems to be more dependable than dropping
518+ // the entire keyspace at once if it has many tables.
519+ if(ksm.getTables().size() > 10) {
520+ for (TableMetadata table : ksm.getTables()) {
521+ logger.debug("Dropping table {}.{}.", keyspace, table.getName());
522+ session.execute("DROP TABLE " + keyspace + "." + table.getName());
523+ }
524+ }
525+ }
526+ logger.debug("Dropping keyspace {}.", keyspace);
515527 session.execute("DROP KEYSPACE " + keyspace);
516528 } finally {
517529 cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(currentTimeout);
518530 }
519531 }
520532 }
521-
522533 }
523534
524535 public static class CCMCluster {