Package com.datastax.driver.core

Examples of com.datastax.driver.core.Session$State


    public void testSetup() throws Exception {
        //tell the method story as it happens: mock or create dependencies and configure
        //those dependencies to get the method under test to completion
        DatabaseType databaseType = DatabaseType.Postgres;
        EntityManager mockEntityManager = mock(EntityManager.class);
        Session mockCassandraSession = mock(Session.class);

        DataMigratorConfiguration mockConfig = PowerMockito.mock(DataMigratorConfiguration.class);
        PowerMockito.whenNew(DataMigratorConfiguration.class)
            .withArguments(eq(mockEntityManager), eq(mockCassandraSession), eq(databaseType), eq(false)).thenReturn(mockConfig);
View Full Code Here


        //tell the method story as it happens: mock or create dependencies and configure
        //those dependencies to get the method under test to completion
        DatabaseType databaseType = DatabaseType.Postgres;

        EntityManager mockEntityManager = mock(EntityManager.class);
        Session mockCassandraSession = mock(Session.class);
        DataMigratorConfiguration mockConfig = PowerMockito.mock(DataMigratorConfiguration.class);
        PowerMockito.whenNew(DataMigratorConfiguration.class)
            .withArguments(eq(mockEntityManager), eq(mockCassandraSession), eq(databaseType), eq(false)).thenReturn(mockConfig);

        when(mockConfig.isRunRawDataMigration()).thenReturn(true);
View Full Code Here

        //tell the method story as it happens: mock or create dependencies and configure
        //those dependencies to get the method under test to completion
        DatabaseType databaseType = DatabaseType.Postgres;

        EntityManager mockEntityManager = mock(EntityManager.class);
        Session mockCassandraSession = mock(Session.class);
        DataMigratorConfiguration mockConfig = PowerMockito.mock(DataMigratorConfiguration.class);
        PowerMockito.whenNew(DataMigratorConfiguration.class)
            .withArguments(eq(mockEntityManager), eq(mockCassandraSession), eq(databaseType), eq(false)).thenReturn(mockConfig);

        when(mockConfig.isRunRawDataMigration()).thenReturn(false);
View Full Code Here

    private RateLimiter getRateLimiter(int warmupTime) {
        return RateLimiter.create(calculateRequestLimit(), warmupTime, TimeUnit.MINUTES);
    }

    public void registerNewSession(Session newWrappedSession) {
        Session oldWrappedSession = this.wrappedSession;

        this.wrappedSession = newWrappedSession;
        this.wrappedSession.getCluster().register(this);

        oldWrappedSession.getCluster().unregister(this);

        // initial waiting before the first check
        try {
            Thread.sleep(60000L);
        } catch (InterruptedException e) {
            // nothing
        }
        oldWrappedSession.shutdown();
    }
View Full Code Here

    }
    CassandraVirtualDataWindow result = null;
    synchronized (_cluster) {
      try {
        _log.info("Started connecting to cluster...");
        final Session session = _cluster.connect(_configuration
            .getKeyspace());
        _log.info("Finished connecting to cluster...");

        result = new CassandraVirtualDataWindow(session,
            _configuration.getTable(), context);
View Full Code Here

  }

  private void createKeyspace(String node, String keyspace) throws Exception {

    Session session = null;
    Exception error = null;
    try {
      _log.info("Started checking whether keyspace {} exists...",
          keyspace);
      session = _rootCluster.connect(keyspace);
      _log.info("Finished checking whether keyspace {} exists...",
          keyspace);
      _log.info("Keyspace {} exists, nothing to do.", keyspace);
    }
    // Keyspace does not exist, so session is not null...
    catch (AlreadyExistsException ae) {
    }
    // Keyspace does not exist, so we try to create it.
    // In that case, session is null
    catch (InvalidQueryException ae) {
    }
    // Unknown exception -> error
    catch (Exception e) {
      _log.error("Unexcpected Exception when checking for keyspace {}!",
          keyspace, e);
      error = e;
    }

    if (session == null && error == null) {
      _log.info("Finished checking whether keyspace {} exists...",
          keyspace);
      _log.info("Keyspace does not yet {} exist, trying to create it",
          keyspace);
      try {
        _log.info("Started creating keyspace {} ...", keyspace);
        session = _rootCluster.connect();

        final String query = String.format("" + "CREATE keyspace %s "
            + "WITH replication = "
            + "{'class': 'SimpleStrategy', "
            + "'replication_factor' : 3}", keyspace);
        session.execute(query);
        _log.info("Finished creating keyspace {} .", keyspace);
      } catch (Exception e) {
        _log.error("Error creating keyspace {}", keyspace, e);
        error = e;
      }
      // In any case, shut down the session for the root user.
      finally {
        if (session != null) {
          _log.info("Started shutting down session for creating keyspace ...");
          session.shutdown();
          _log.info("Finished shutting down session for creating keyspace.");
        }
      }
    }
    if (error != null) {
View Full Code Here

  }

  private void createTable(VirtualDataWindowContext context) throws Exception {

    Session session = null;
    Exception error = null;
    final String table = context.getNamedWindowName();
    final String keyspace = context.getViewFactoryContext()
        .getNamespaceName();

    boolean tableExists = true;
    try {
      _log.info("Started checking whether table {} exists...", table);
      session = _rootCluster.connect(keyspace);
      session.execute(String.format("SELECT * FROM %s LIMIT 10", table));

      _log.info("Finished checking whether table {} exists...", table);
      _log.info("Table {} exists, nothing to do.", table);
    }
    // Keyspace does not exist, so we try to create it.
    catch (InvalidQueryException ae) {
      tableExists = false;
    }
    // Unknown exception -> error
    catch (Exception e) {
      tableExists = false;
      _log.error("Unexcpected Exception when checking for table {}!",
          table, e);
      error = e;
    }

    if (error == null) {
      _log.info("Finished checking whether table {} exists...", table);
      try {
        session = _rootCluster.connect(keyspace);
        if (!tableExists) {
          _log.info(
              "Table does not yet {} exist, trying to create it",
              table);

          try {
            _log.info("Started creating table {} ...", table);
            final String createQuery = QueryStringBuilder
                .createCreateTableQuery(context);
            _log.debug("Executing create query: {}", createQuery);
            session.execute(createQuery);
            _log.info("Finished creating table {} .", table);
          } catch (Exception e) {
            _log.error("Error creating table {} .", table);
            error = e;
          }
        }

        if (_username != null && error == null) {
          try {
            _log.info("Started granting rights to table {} ...",
                table);
            final String grantQuery = String.format(
                "GRANT ALL on %s TO %s", table, _username);
            _log.debug("Executing grant query: {}", grantQuery);
            session.execute(grantQuery);
            _log.info("Finished granting rights to table {}.",
                table);
          } catch (Exception e) {
            _log.error("Error granting rights to table {}.", table,
                e);
            error = e;
          }
        }

      } catch (Exception e) {
        _log.error("Error creating table {}", table, e);
        error = e;
      }
      // In any case, shut down the session for the root user.
      finally {
        if (session != null) {
          _log.info("Started shutting down session for creating table ...");
          session.shutdown();
          _log.info("Finished shutting down session for creating table.");
        }
      }
    }
    if (error != null) {
View Full Code Here

    }
    CassandraVirtualDataWindow result = null;
    synchronized (_cluster) {
      try {
        _log.info("Started connecting to cluster...");
        final Session session = _cluster.connect(_configuration
            .getKeyspace());
        _log.info("Finished connecting to cluster...");

        createTable(context);
View Full Code Here

    }
    CassandraVirtualDataWindow result = null;
    synchronized (_cluster) {
      try {
        _log.info("Started connecting to cluster...");
        final Session session = _cluster.connect(_configuration
            .getKeyspace());
        _log.info("Finished connecting to cluster...");
        result = new CassandraVirtualDataWindow(session, context);
      } catch (Exception e) {
        _log.error("Error connecting to cluster!");
View Full Code Here

    public <T> T executeWithSession(String schemaName, SessionCallable<T> sessionCallable)
    {
        NoHostAvailableException lastException = null;
        for (int i = 0; i < 2; i++) {
            Session session = getSession(schemaName);
            try {
                return sessionCallable.executeWithSession(session);
            }
            catch (NoHostAvailableException e) {
                lastException = e;
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.Session$State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.