Skip to content

Commit

Permalink
Added unit tests for new repository method...
Browse files Browse the repository at this point in the history
  • Loading branch information
bargenilesh committed Mar 28, 2017
1 parent 974442e commit 13008fe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ public void pushAssignmentsToStaging(String type, String exception, Collection<S
LOGGER.debug("Finished pushAssignmentsToStaging");
} catch (Exception e) {
LOGGER.error("Error occurred while pushAssignmentsToStaging", e);
throw new RepositoryException("Error occurred while pushAssignmentsToStaging", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.intuit.wasabi.repository.cassandra.accessor.index.PageExperimentIndexAccessor;
import com.intuit.wasabi.repository.cassandra.pojo.count.BucketAssignmentCount;
import com.intuit.wasabi.repository.cassandra.pojo.index.ExperimentUserByUserIdContextAppNameExperimentId;
import org.apache.cassandra.utils.UUIDGen;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Before;
Expand Down Expand Up @@ -81,6 +82,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;

import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Maps.newHashMap;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.notNullValue;
Expand Down Expand Up @@ -556,6 +558,42 @@ public void testPushAssignmentToStaging() {
.insertBy(eq("type"), eq("string1"), eq("string2"));
}

@Test
public void testPushAssignmentsToStaging() {
//------ Input
List<String> messages = newArrayList("Msg1", "Msg2", "Msg3");

//------ Mocking interacting calls
ResultSet genericResultSet = mock(ResultSet.class);
when(driver.getSession()).thenReturn(mock(Session.class));
when(driver.getSession().execute(any(BatchStatement.class))).thenReturn(genericResultSet);

//----- Actual call
repository.pushAssignmentsToStaging("type", "string1", messages);

//----- Verify result
verify(stagingAccessor, times(3)).batchInsertBy(any(UUID.class), eq("type"), eq("string1"), any(String.class));
}

@Test
public void testPushAssignmentsToStagingWriteException() {
//------ Input
List<String> messages = newArrayList("Msg1", "Msg2", "Msg3");

//------ Mocking interacting calls
doThrow(WriteTimeoutException.class).when(stagingAccessor).batchInsertBy(any(UUID.class), eq("type"), eq("string1"), any(String.class));
ResultSet genericResultSet = mock(ResultSet.class);
when(driver.getSession()).thenReturn(mock(Session.class));
when(driver.getSession().execute(any(BatchStatement.class))).thenReturn(genericResultSet);

//----- Verify expected exception
thrown.expect(RepositoryException.class);
thrown.expectMessage("Error occurred while pushAssignmentsToStaging");

//----- Actual call
repository.pushAssignmentsToStaging("type", "string1", messages);
}

@Test
public void testPushAssignmentToStagingrWriteException() {
doThrow(WriteTimeoutException.class).when(stagingAccessor)
Expand Down

0 comments on commit 13008fe

Please sign in to comment.