Refine search
/** * Add field use_raw_configuration_schema to endpointProfile that used to support devices using * SDK version 0.9.0 */ public void transform() { //mongo MongoClient client = new MongoClient(host); MongoDatabase database = client.getDatabase(dbName); MongoCollection<Document> endpointProfile = database.getCollection("endpoint_profile"); endpointProfile.updateMany(new Document(), eq("$set", eq("use_raw_schema", false))); //cassandra Cluster cluster = Cluster.builder().addContactPoint(host).build(); Session session = cluster.connect(dbName); session.execute("ALTER TABLE ep_profile ADD use_raw_schema boolean"); session.close(); cluster.close(); } }
/** * Returns Cassandra session and its generation number. * * @return Wrapper object providing Cassandra session and its generation number. */ private synchronized WrappedSession session() { if (wrapperSes != null) return wrapperSes; Session ses = SessionPool.get(this); if (ses != null) { this.wrapperSes = new WrappedSession(ses, generation); return this.wrapperSes; } synchronized (sesStatements) { sesStatements.clear(); } try { ses = builder.build().connect(); generation++; this.wrapperSes = new WrappedSession(ses, generation); } catch (Throwable e) { throw new IgniteException("Failed to establish session with Cassandra database", e); } return this.wrapperSes; }
@Test(groups = "short") public void testMissingRpcAddressAtStartup() throws Exception { deleteNode2RpcAddressFromNode1(); // Use only one contact point to make sure that the control connection is on node1 Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints().get(0)) .withPort(ccm().getBinaryPort()) .build()); cluster.connect(); // Since node2's RPC address is unknown on our control host, it should have been ignored assertEquals(cluster.getMetrics().getConnectedToHosts().getValue().intValue(), 1); assertNull(cluster.getMetadata().getHost(getContactPointsWithPorts().get(1))); }
@Override protected void load() { String hostIp = EmbeddedCassandraServerHelper.getHost(); int port = EmbeddedCassandraServerHelper.getNativeTransportPort(); cluster = new Cluster.Builder().addContactPoints(hostIp).withPort(port).withSocketOptions(getSocketOptions()) .build(); session = cluster.connect(); CQLDataLoader dataLoader = new CQLDataLoader(session); dataLoader.load(dataSet); session = dataLoader.getSession(); }
private void startUp() { int port = 9042; String[] seeds; if (configuration.containsKey(CONTACT_POINTS)) { seeds = configuration.get(CONTACT_POINTS).split(","); } else { seeds = new String[] {LOCALHOST}; } Cluster cluster = new Cluster.Builder() .addContactPoints(seeds) .withPort(port) .build(); String keySpace = configuration.get(KEY_SPACE); if (keySpace == null || keySpace.isEmpty()) { keySpace=DEFAULT_KEYSPACE; } session = Optional.of(cluster.connect(keySpace)); dataAccess = new DataAccess(session.get()); }
@Test(groups = "short") public void should_connect_with_credentials() { PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra")); Cluster cluster = Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withAuthProvider(authProvider) .build(); cluster.connect(); verify(authProvider, atLeastOnce()) .newAuthenticator( findHost(cluster, 1).getSocketAddress(), "org.apache.cassandra.auth.PasswordAuthenticator"); assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount()) .isEqualTo(0); }
private void connectInternal() { try { Cluster cluster = config.createBuilder().build(); cassandraSession = cluster.connect(keySpace); cassandraMetrics = cluster.getMetrics(); connected.set(true); } catch (Exception e) { LOGGER.error("Error connection to Cassandra" + e.getMessage()); if (pool != null) { pool.shutdownNow(); pool = null; } if (cassandraSession != null) { cassandraSession.close(); if (cassandraSession.getCluster() != null) cassandraSession.getCluster().close(); } connected.set(false); } }
Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withCodecRegistry(codecRegistry) .build()); Session session = cluster.connect(keyspace); setUpTupleTypes(cluster); codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
@BeforeMethod(groups = {"short", "unit"}) public void setUp() { originalSlow = slow.getLevel(); originalError = error.getLevel(); slow.setLevel(INFO); error.setLevel(INFO); slow.addAppender(slowAppender = new MemoryAppender()); error.addAppender(errorAppender = new MemoryAppender()); queryLogger = null; cluster = createClusterBuilder().withRetryPolicy(FallthroughRetryPolicy.INSTANCE).build(); session = cluster.connect(); }
Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withCredentials("bogus", "bogus") .build()); cluster.connect(); fail("Should throw AuthenticationException when attempting to connect"); } catch (AuthenticationException e) { try { cluster.connect(); fail("Should throw IllegalStateException when attempting to connect again."); } catch (IllegalStateException e1) {
Cluster cluster = register( Cluster.builder() .addContactPoints(getContactPoints()) .withPort(ccm().getBinaryPort()) .withCodecRegistry(codecRegistry) .build()); Session session = cluster.connect(keyspace); setUpTupleTypes(cluster); codecRegistry.register(new LocationCodec(TypeCodec.tuple(locationType)));
/** * When no consistency level is defined the default of LOCAL_ONE should be used. * * @test_category consistency */ @Test(groups = "short") public void should_use_global_default_cl_when_none_specified() throws Throwable { // Build a cluster with no CL level set in the query options. Cluster cluster = builder().build(); try { Session session = cluster.connect(); // Construct unique simple statement query, with no CL defined. // Check to ensure String queryString = "default_cl"; Query clQuery = executeSimple(session, queryString, null, null); assertTrue(clQuery.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); // Check prepared statement default CL String prepareString = "prepared_default_cl"; PreparedStatementExecution pse = executePrepared(session, prepareString, null, null); assertTrue(pse.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); // Check batch statement default CL String batchStateString = "batch_default_cl"; BatchExecution batch = executeBatch(session, batchStateString, null, null); assertTrue(batch.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString())); } finally { cluster.close(); } }
public void should_detect_cluster_init_failure_and_close_cluster() { Cluster cluster = Cluster.builder() .addContactPointsWithPorts(new InetSocketAddress("127.0.0.1", 65534)) .withNettyOptions(nonQuietClusterCloseOptions) .build(); try { cluster.connect(); fail("Should not have been able to connect."); } catch (NoHostAvailableException e) { try { cluster.connect(); fail("Should error when connect is called."); } catch (IllegalStateException e1) {
@BeforeMethod(groups = "short") public void setUp() { sCluster = ScassandraCluster.builder().withNodes(4).build(); sCluster.init(); cluster = Cluster.builder() .addContactPoints(sCluster.address(1).getAddress()) .withPort(sCluster.getBinaryPort()) .withLoadBalancingPolicy(lbSpy) .withNettyOptions(nonQuietClusterCloseOptions) .build(); session = cluster.connect(); // Reset invocations before entering test. Mockito.reset(lbSpy); }