@Test
 // 50 times: 597 mills.
 public void listKeyspaces() throws Exception {
   int count = 50;
   //
   long beg = System.currentTimeMillis();
   for (int i = 0; i < count; i++) {
     CtSession ctSession = ctSessionFactory.openSession();
     System.out.println(ctSession);
     //
     List<KsDef> kds = ctSession.describe_keyspaces();
     for (KsDef kd : kds) {
       StringBuilder buffer = new StringBuilder();
       buffer.append("[");
       buffer.append(kd.getName());
       buffer.append("] ");
       List<CfDef> cds = kd.getCf_defs();
       int size = cds.size();
       for (int j = 0; j < size; j++) {
         buffer.append(cds.get(j).getName());
         if (j < size - 1) {
           buffer.append(", ");
         }
       }
       //
       System.out.println(buffer);
     }
     ctSessionFactory.closeSession();
   }
   long end = System.currentTimeMillis();
   System.out.println(count + " times: " + (end - beg) + " mills. ");
 }
Exemplo n.º 2
0
  public String addKeyspace(final KsDef keyspaceDefinition) throws Exception {
    if (logger.isInfoEnabled()) logger.info("Adding keyspace '{}'", keyspaceDefinition.getName());
    IManagerOperation<String> operation =
        new IManagerOperation<String>() {
          @Override
          public String execute(Client conn) throws Exception {
            return conn.system_add_keyspace(keyspaceDefinition);
          }
        };
    String schemaVersion = tryOperation(operation);
    if (logger.isInfoEnabled())
      logger.info(
          "Added keyspace '{}', schema version is now '{}'",
          new Object[] {keyspaceDefinition.getName(), schemaVersion});

    return schemaVersion;
  }