Package com.datastax.driver.core

Examples of com.datastax.driver.core.Session


    @Test(groups = "short",
        expectedExceptions = IllegalArgumentException.class,
        expectedExceptionsMessageRegExp = "Error creating mapper for class Group, the @Table annotation declares no default keyspace, and the session is not currently logged to any keyspace")
    public void should_throw_a_meaningful_error_message_when_no_default_table_keyspace_and_session_not_logged() {
        Session session2 = cluster.connect();
        MappingManager manager = new MappingManager(session2);
        manager.mapper(Group.class);
    }
View Full Code Here


    @Test(groups = "short",
        expectedExceptions = IllegalArgumentException.class,
        expectedExceptionsMessageRegExp = "Error creating UDT mapper for class GroupName, the @UDT annotation declares no default keyspace, and the session is not currently logged to any keyspace")
    public void should_throw_a_meaningful_error_message_when_no_default_udt_keyspace_and_session_not_logged() {
        Session session2 = cluster.connect();
        MappingManager manager = new MappingManager(session2);
        manager.udtMapper(GroupName.class);
    }
View Full Code Here

    return null;
  }

  @Override
  public ResponseData get(Object rkey, Object colName) throws OperationException {
    Session session = DataStaxClientConnection.instance.session();
    TableMetadata tm = DataStaxClientConnection.instance.getKeyspaceMetadata().getTable(cfName);
    String partitionKey = tm.getPartitionKey().get(0).getName();
   
    Query query = QueryBuilder.select(colName.toString()).from(cfName).where(QueryBuilder.eq(partitionKey, rkey)).limit(1000000)
        .setConsistencyLevel(ConsistencyLevel.valueOf(com.netflix.jmeter.properties.Properties.instance.cassandra.getReadConsistency()));
   
    ResultSetFuture rs = session.executeAsync(query);

    int size = 0;
    try {
      Row row = rs.getUninterruptibly(1000000, TimeUnit.MILLISECONDS).one();
      size = row != null ? row.getBytesUnsafe(colName.toString()).capacity() : 0;
View Full Code Here

    return null;
  }

  @Override
  public ResponseData getComposite(String key, String compositeColName) throws OperationException {
    Session session = DataStaxClientConnection.instance.session();

    TableMetadata tm = DataStaxClientConnection.instance.getKeyspaceMetadata().getTable(cfName);
    String partitionKey = tm.getPartitionKey().get(0).getName();
    Object partitionValue = key;

    String[] colList = compositeColName.split(":");
    String clusteredKey = colList[0];
    String clusteredValue = colList[1];
    String colName = colList[2];
   
    Long start = System.nanoTime();
   
    ResultSetFuture rs = session.executeAsync(QueryBuilder.select(colName).from(cfName).where(QueryBuilder.eq(partitionKey, partitionValue))
        .and(QueryBuilder.eq(clusteredKey, clusteredValue)).limit(1000000));
   
    int size = 0;
   
    try {
View Full Code Here

        EntityManagerFactory entityManagerFactory = this.createEntityManagerFactory();
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        log.debug("Done creating Entity Manager");

        log.debug("Creating Cassandra session");
        Session cassandraSession = this.createCassandraSession();
        log.debug("Done creating Cassandra session");

        DatabaseType databaseType = DatabaseType.Postgres;
        if (configuration.get(sqlServerTypeOption) != null) {
            databaseType = (DatabaseType) configuration.get(sqlServerTypeOption);
View Full Code Here

        }

        LOG.info("Initializing storage client subsystem");

        try {
            Session wrappedSession = createSession();
            session = new StorageSession(wrappedSession);

            storageClusterMonitor = new StorageClusterMonitor(session);
            session.addStorageStateListener(storageClusterMonitor);
View Full Code Here

        String password = settings.get(SystemSetting.STORAGE_PASSWORD);

        if ((username != null && !username.equals(this.cachedStorageUsername))
            || (password != null && !password.equals(this.cachedStoragePassword))) {

            Session wrappedSession;
            try {
                wrappedSession = createSession();
            } catch (NoHostAvailableException e) {
                if (cluster != null) {
                    cluster.shutdown();
View Full Code Here

        //those dependencies to get the method under test to completion
        DatabaseType databaseType = DatabaseType.Oracle;
        DataMigratorConfiguration mockConfig = mock(DataMigratorConfiguration.class);
        when(mockConfig.getDatabaseType()).thenReturn(databaseType);

        Session mockCassandraSession = mock(Session.class);
        when(mockConfig.getSession()).thenReturn(mockCassandraSession);

        MetricsIndexMigrator mockMetricsIndexUpdateAccumulator = mock(MetricsIndexMigrator.class);
        PowerMockito.whenNew(MetricsIndexMigrator.class)
            .withArguments(eq(MigrationTable.ONE_HOUR), eq(mockConfig))
            .thenReturn(mockMetricsIndexUpdateAccumulator);

        EntityManager mockEntityManager = mock(EntityManager.class);
        when(mockConfig.getEntityManager()).thenReturn(mockEntityManager);

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class).withArguments(eq(mockEntityManager), eq(databaseType), any())
            .thenReturn(mockDataSource);

        List<Object[]> resultList = new ArrayList<Object[]>();
        resultList.add(new Object[] { 100, 100, 100, 100, 100 });
        resultList.add(new Object[] { 100, System.currentTimeMillis() - 100l, 100, 100, 100 });

        for (int index = 0; index < 15; index++) {
            when(mockDataSource.getData(eq(0), anyInt())).thenReturn(resultList);
            when(mockDataSource.getData(eq(2), anyInt())).thenReturn(new ArrayList<Object[]>());
        }

        ResultSetFuture mockResultSetFuture = mock(ResultSetFuture.class);
        when(mockCassandraSession.executeAsync(any(Query.class))).thenReturn(mockResultSetFuture);

        //create object to test and inject required dependencies
        AggregateDataMigrator objectUnderTest = new AggregateDataMigrator(MigrationTable.ONE_HOUR, mockConfig);

        //run code under test
View Full Code Here

        //those dependencies to get the method under test to completion
        DatabaseType databaseType = DatabaseType.Oracle;
        DataMigratorConfiguration mockConfig = mock(DataMigratorConfiguration.class);
        when(mockConfig.getDatabaseType()).thenReturn(databaseType);

        Session mockCassandraSession = mock(Session.class);
        when(mockConfig.getSession()).thenReturn(mockCassandraSession);

        MetricsIndexMigrator mockMetricsIndexUpdateAccumulator = mock(MetricsIndexMigrator.class);
        PowerMockito.whenNew(MetricsIndexMigrator.class).withArguments(eq(MigrationTable.RAW), eq(mockConfig))
            .thenReturn(mockMetricsIndexUpdateAccumulator);

        EntityManager mockEntityManager = mock(EntityManager.class);
        when(mockConfig.getEntityManager()).thenReturn(mockEntityManager);

        org.hibernate.Session mockHibernateSession = mock(org.hibernate.Session.class);
        when(mockEntityManager.getDelegate()).thenReturn(mockHibernateSession);
        SessionFactory mockSessionFactory = mock(SessionFactory.class);
        when(mockHibernateSession.getSessionFactory()).thenReturn(mockSessionFactory);
        StatelessSession mockStatelessSession = mock(StatelessSession.class);
        when(mockSessionFactory.openStatelessSession()).thenReturn(mockStatelessSession);

        org.hibernate.SQLQuery mockQuery = mock(org.hibernate.SQLQuery.class);
        when(mockStatelessSession.createSQLQuery(any(String.class))).thenReturn(mockQuery);

        when(mockQuery.uniqueResult()).thenReturn("1000");

        ScrollableDataSource mockDataSource = mock(ScrollableDataSource.class);
        PowerMockito.whenNew(ScrollableDataSource.class).withArguments(eq(mockEntityManager), eq(databaseType), any())
            .thenReturn(mockDataSource);

        List<Object[]> resultList = new ArrayList<Object[]>();
        resultList.add(new Object[] { 100, 100, 100 });
        resultList.add(new Object[] { 100, System.currentTimeMillis() - 100l, 100 });

        for (int index = 0; index < 15; index++) {
            when(mockDataSource.getData(eq(0), anyInt())).thenReturn(resultList);
            when(mockDataSource.getData(eq(2), anyInt())).thenReturn(new ArrayList<Object[]>());
        }

        ResultSetFuture mockResultSetFuture = mock(ResultSetFuture.class);
        when(mockCassandraSession.executeAsync(any(Query.class))).thenReturn(mockResultSetFuture);

        //create object to test and inject required dependencies
        RawDataMigrator objectUnderTest = new RawDataMigrator(mockConfig);

        //run code under test
View Full Code Here

            public void onRemove(Host host) {
                log.info("host " + host + " REMOVED");
            }
        });

        Session session = cluster.connect("rhq");
        StorageSession storageSession = new StorageSession(session);

        MetricsDAO dao = new MetricsDAO(storageSession, new MetricsConfiguration());

        while (true) {
View Full Code Here

TOP

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

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.