com.datastax.driver.core.Configuration Java Examples
The following examples show how to use
com.datastax.driver.core.Configuration.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PutCassandraQLTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password) { Cluster mockCluster = mock(Cluster.class); try { Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); when(mockCluster.connect()).thenReturn(mockSession); when(mockCluster.connect(anyString())).thenReturn(mockSession); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); ResultSetFuture future = mock(ResultSetFuture.class); ResultSet rs = CassandraQueryTestUtil.createMockResultSet(); PreparedStatement ps = mock(PreparedStatement.class); when(mockSession.prepare(anyString())).thenReturn(ps); BoundStatement bs = mock(BoundStatement.class); when(ps.bind()).thenReturn(bs); when(future.getUninterruptibly()).thenReturn(rs); try { doReturn(rs).when(future).getUninterruptibly(anyLong(), any(TimeUnit.class)); } catch (TimeoutException te) { throw new IllegalArgumentException("Mocked cluster doesn't time out"); } if (exceptionToThrow != null) { doThrow(exceptionToThrow).when(mockSession).executeAsync(anyString()); doThrow(exceptionToThrow).when(mockSession).executeAsync(any(Statement.class)); } else { when(mockSession.executeAsync(anyString())).thenReturn(future); when(mockSession.executeAsync(any(Statement.class))).thenReturn(future); } when(mockSession.getCluster()).thenReturn(mockCluster); } catch (Exception e) { fail(e.getMessage()); } return mockCluster; }
Example #2
Source File: AbstractCassandraProcessorTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password) { Cluster mockCluster = mock(Cluster.class); Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); return mockCluster; }
Example #3
Source File: QueryCassandraTest.java From localization_nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password) { Cluster mockCluster = mock(Cluster.class); try { Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); Session mockSession = mock(Session.class); when(mockCluster.connect()).thenReturn(mockSession); when(mockCluster.connect(anyString())).thenReturn(mockSession); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); ResultSetFuture future = mock(ResultSetFuture.class); ResultSet rs = CassandraQueryTestUtil.createMockResultSet(); when(future.getUninterruptibly()).thenReturn(rs); try { doReturn(rs).when(future).getUninterruptibly(anyLong(), any(TimeUnit.class)); } catch (TimeoutException te) { throw new IllegalArgumentException("Mocked cluster doesn't time out"); } if (exceptionToThrow != null) { when(mockSession.executeAsync(anyString())).thenThrow(exceptionToThrow); } else { when(mockSession.executeAsync(anyString())).thenReturn(future); } } catch (Exception e) { fail(e.getMessage()); } return mockCluster; }
Example #4
Source File: CassandraOperatorTest.java From attic-apex-malhar with Apache License 2.0 | 5 votes |
@Test public void testCassandraProtocolVersion() { TestOutputOperator outputOperator = setupForOutputOperatorTest(); outputOperator.getStore().setProtocolVersion("v2"); outputOperator.setup(context); Configuration config = outputOperator.getStore().getCluster().getConfiguration(); Assert.assertEquals("Procotol version was not set to V2.", ProtocolVersion.V2, config.getProtocolOptions().getProtocolVersion()); }
Example #5
Source File: PutCassandraRecordTest.java From nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password, String compressionType) { Cluster mockCluster = mock(Cluster.class); try { Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); when(mockCluster.connect()).thenReturn(mockSession); when(mockCluster.connect(anyString())).thenReturn(mockSession); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); ResultSetFuture future = mock(ResultSetFuture.class); ResultSet rs = CassandraQueryTestUtil.createMockResultSet(); PreparedStatement ps = mock(PreparedStatement.class); when(mockSession.prepare(anyString())).thenReturn(ps); BoundStatement bs = mock(BoundStatement.class); when(ps.bind()).thenReturn(bs); when(future.getUninterruptibly()).thenReturn(rs); try { doReturn(rs).when(future).getUninterruptibly(anyLong(), any(TimeUnit.class)); } catch (TimeoutException te) { throw new IllegalArgumentException("Mocked cluster doesn't time out"); } if (exceptionToThrow != null) { doThrow(exceptionToThrow).when(mockSession).executeAsync(anyString()); doThrow(exceptionToThrow).when(mockSession).executeAsync(any(Statement.class)); } else { when(mockSession.executeAsync(anyString())).thenReturn(future); when(mockSession.executeAsync(any(Statement.class))).thenReturn(future); } when(mockSession.getCluster()).thenReturn(mockCluster); } catch (Exception e) { fail(e.getMessage()); } return mockCluster; }
Example #6
Source File: PutCassandraQLTest.java From nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password, String compressionType) { Cluster mockCluster = mock(Cluster.class); try { Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); when(mockCluster.connect()).thenReturn(mockSession); when(mockCluster.connect(anyString())).thenReturn(mockSession); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); ResultSetFuture future = mock(ResultSetFuture.class); ResultSet rs = CassandraQueryTestUtil.createMockResultSet(); PreparedStatement ps = mock(PreparedStatement.class); when(mockSession.prepare(anyString())).thenReturn(ps); BoundStatement bs = mock(BoundStatement.class); when(ps.bind()).thenReturn(bs); when(future.getUninterruptibly()).thenReturn(rs); try { doReturn(rs).when(future).getUninterruptibly(anyLong(), any(TimeUnit.class)); } catch (TimeoutException te) { throw new IllegalArgumentException("Mocked cluster doesn't time out"); } if (exceptionToThrow != null) { doThrow(exceptionToThrow).when(mockSession).executeAsync(anyString()); doThrow(exceptionToThrow).when(mockSession).executeAsync(any(Statement.class)); } else { when(mockSession.executeAsync(anyString())).thenReturn(future); when(mockSession.executeAsync(any(Statement.class))).thenReturn(future); } when(mockSession.getCluster()).thenReturn(mockCluster); } catch (Exception e) { fail(e.getMessage()); } return mockCluster; }
Example #7
Source File: AbstractCassandraProcessorTest.java From nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password, String compressionType) { Cluster mockCluster = mock(Cluster.class); Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); return mockCluster; }
Example #8
Source File: QueryCassandraTest.java From nifi with Apache License 2.0 | 5 votes |
@Override protected Cluster createCluster(List<InetSocketAddress> contactPoints, SSLContext sslContext, String username, String password, String compressionType) { Cluster mockCluster = mock(Cluster.class); try { Metadata mockMetadata = mock(Metadata.class); when(mockMetadata.getClusterName()).thenReturn("cluster1"); when(mockCluster.getMetadata()).thenReturn(mockMetadata); Session mockSession = mock(Session.class); when(mockCluster.connect()).thenReturn(mockSession); when(mockCluster.connect(anyString())).thenReturn(mockSession); Configuration config = Configuration.builder().build(); when(mockCluster.getConfiguration()).thenReturn(config); ResultSetFuture future = mock(ResultSetFuture.class); ResultSet rs = CassandraQueryTestUtil.createMockResultSet(); when(future.getUninterruptibly()).thenReturn(rs); try { doReturn(rs).when(future).getUninterruptibly(anyLong(), any(TimeUnit.class)); } catch (TimeoutException te) { throw new IllegalArgumentException("Mocked cluster doesn't time out"); } if (exceptionToThrow != null) { when(mockSession.executeAsync(anyString())).thenThrow(exceptionToThrow); } else { when(mockSession.executeAsync(anyString())).thenReturn(future); } } catch (Exception e) { fail(e.getMessage()); } return mockCluster; }
Example #9
Source File: CassandraClusterCreatorTest.java From spring-cloud-connectors with Apache License 2.0 | 5 votes |
@Test public void shouldCreateClusterWithConfig() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142); CassandraClusterConfig config = new CassandraClusterConfig(); config.setCompression(ProtocolOptions.Compression.NONE); config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234)); config.setQueryOptions(new QueryOptions()); config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED); config.setLoadBalancingPolicy(new RoundRobinPolicy()); config.setReconnectionPolicy(new ConstantReconnectionPolicy(1)); config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); config.setSocketOptions(new SocketOptions()); Cluster cluster = creator.create(info, config); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getCompression(), is(config.getCompression())); assertThat(configuration.getQueryOptions(), is(config.getQueryOptions())); assertThat(configuration.getSocketOptions(), is(config.getSocketOptions())); Policies policies = configuration.getPolicies(); assertThat(policies.getLoadBalancingPolicy(), is(config.getLoadBalancingPolicy())); assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy())); assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy())); }
Example #10
Source File: CassandraClusterCreatorTest.java From spring-cloud-connectors with Apache License 2.0 | 3 votes |
@Test public void shouldCreateCluster() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142); Cluster cluster = creator.create(info, null); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getAuthProvider(), is(AuthProvider.NONE)); }
Example #11
Source File: CassandraClusterCreatorTest.java From spring-cloud-connectors with Apache License 2.0 | 3 votes |
@Test public void shouldCreateClusterWithAuthentication() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142, "walter", "white"); Cluster cluster = creator.create(info, null); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getAuthProvider(), is(instanceOf(PlainTextAuthProvider.class))); }