use of org.apache.ignite.cache.store.cassandra.session.CassandraSessionImpl in project ignite by apache.
the class CassandraSessionImplTest method executeFailureTest.
/**
*/
@SuppressWarnings("unchecked")
@Test
public void executeFailureTest() {
Session session1 = mock(Session.class);
Session session2 = mock(Session.class);
when(session1.prepare(nullable(String.class))).thenReturn(preparedStatement1);
when(session2.prepare(nullable(String.class))).thenReturn(preparedStatement2);
ResultSetFuture rsFuture = mock(ResultSetFuture.class);
ResultSet rs = mock(ResultSet.class);
Iterator it = mock(Iterator.class);
when(it.hasNext()).thenReturn(true);
when(it.next()).thenReturn(mock(Row.class));
when(rs.iterator()).thenReturn(it);
when(rsFuture.getUninterruptibly()).thenReturn(rs);
/* @formatter:off */
when(session1.executeAsync(any(Statement.class))).thenThrow(new InvalidQueryException("You may have used a PreparedStatement that was created with another Cluster instance")).thenThrow(new RuntimeException("this session should be refreshed / recreated"));
when(session2.executeAsync(boundStatement1)).thenThrow(new InvalidQueryException("You may have used a PreparedStatement that was created with another Cluster instance"));
when(session2.executeAsync(boundStatement2)).thenReturn(rsFuture);
/* @formatter:on */
Cluster cluster = mock(Cluster.class);
when(cluster.connect()).thenReturn(session1).thenReturn(session2);
when(session1.getCluster()).thenReturn(cluster);
when(session2.getCluster()).thenReturn(cluster);
Cluster.Builder builder = mock(Cluster.Builder.class);
when(builder.build()).thenReturn(cluster);
CassandraSessionImpl cassandraSession = new CassandraSessionImpl(builder, null, ConsistencyLevel.ONE, ConsistencyLevel.ONE, 0, mock(IgniteLogger.class));
BatchExecutionAssistant<String, String> batchExecutionAssistant = new MyBatchExecutionAssistant();
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < 10; i++) {
data.add(String.valueOf(i));
}
cassandraSession.execute(batchExecutionAssistant, data);
verify(cluster, times(2)).connect();
verify(session1, times(1)).prepare(nullable(String.class));
verify(session2, times(1)).prepare(nullable(String.class));
assertEquals(10, batchExecutionAssistant.processedCount());
}
Aggregations