Skip to content

Commit

Permalink
fix test to work with change to DataGapRouteReader
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed May 16, 2016
1 parent 631edee commit 268ccff
Showing 1 changed file with 10 additions and 24 deletions.
Expand Up @@ -93,7 +93,7 @@ public void setUp() throws Exception {
nodeChannel.setBatchAlgorithm(DefaultBatchAlgorithm.NAME);
}

protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold) throws Exception {
protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold, List<DataGap> dataGaps) throws Exception {

when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
Expand Down Expand Up @@ -138,6 +138,7 @@ protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold) throws Ex

ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel,
mock(ISqlTransaction.class));
context.setDataGaps(dataGaps);

return new DataGapRouteReader(context, engine);
}
Expand All @@ -151,8 +152,6 @@ public void testTransactionalOrderingWithGaps() throws Exception {

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(2);

DataGapRouteReader dataGapRouteReader = buildReader(50);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, 3));
dataGaps.add(new DataGap(4, Long.MAX_VALUE));
Expand All @@ -164,11 +163,10 @@ public void testTransactionalOrderingWithGaps() throws Exception {
data.add(new Data(4, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN2, null));

when(dataService.findDataGaps()).thenReturn(dataGaps);
when(
sqlTemplate.queryForCursor((String) any(), (ISqlRowMapper<Data>) any(),
(Object[]) any(), (int[]) any())).thenReturn(new ListReadCursor(data));
when(sqlTemplate.queryForCursor((String) any(), (ISqlRowMapper<Data>) any(),
(Object[]) any(), (int[]) any())).thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();

BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
Expand All @@ -192,8 +190,6 @@ public void testTransactionalChannelMaxDataToRoute() throws Exception {

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(100);

DataGapRouteReader dataGapRouteReader = buildReader(50);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));

Expand All @@ -205,11 +201,11 @@ public void testTransactionalChannelMaxDataToRoute() throws Exception {
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(6, null, null, null, TABLE1, null, null, null, TRAN1, null));

when(dataService.findDataGaps()).thenReturn(dataGaps);
ISqlRowMapper<Data> mapper = any();
when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any()))
.thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();

BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
Expand All @@ -233,8 +229,6 @@ public void testTransactionalChannelTwoTransactionsRouted() throws Exception {

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(100);

DataGapRouteReader dataGapRouteReader = buildReader(50);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));

Expand All @@ -246,11 +240,11 @@ public void testTransactionalChannelTwoTransactionsRouted() throws Exception {
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(6, null, null, null, TABLE1, null, null, null, TRAN1, null));

when(dataService.findDataGaps()).thenReturn(dataGaps);
ISqlRowMapper<Data> mapper = any();
when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any()))
.thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();

BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
Expand All @@ -274,8 +268,6 @@ public void testTransactionalChannelReachMaxPeekAheadSizeThreshold() throws Exce

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(100);

DataGapRouteReader dataGapRouteReader = buildReader(0);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));

Expand All @@ -288,13 +280,12 @@ public void testTransactionalChannelReachMaxPeekAheadSizeThreshold() throws Exce
data.add(new Data(6, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(7, null, null, null, TABLE1, null, null, null, TRAN2, null));

when(dataService.findDataGaps()).thenReturn(dataGaps);

ISqlRowMapper<Data> mapper = any();

when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any()))
.thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(0, dataGaps);
dataGapRouteReader.execute();

BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
Expand All @@ -317,8 +308,6 @@ public void testDontPeekAheadWhenPeekAheadQueueIsAlreadyFull() throws Exception

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(5);

DataGapRouteReader dataGapRouteReader = buildReader(100);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));

Expand All @@ -328,13 +317,12 @@ public void testDontPeekAheadWhenPeekAheadQueueIsAlreadyFull() throws Exception
null));
}

when(dataService.findDataGaps()).thenReturn(dataGaps);

ISqlRowMapper<Data> mapper = any();

when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any()))
.thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(100, dataGaps);
dataGapRouteReader.execute();

/*
Expand Down Expand Up @@ -363,8 +351,6 @@ public void testNonTransactionalChannelMaxDataToRoute() throws Exception {

when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_WINDOW)).thenReturn(2);

DataGapRouteReader dataGapRouteReader = buildReader(50);

List<DataGap> dataGaps = new ArrayList<DataGap>();
dataGaps.add(new DataGap(0, Long.MAX_VALUE));

Expand All @@ -375,11 +361,11 @@ public void testNonTransactionalChannelMaxDataToRoute() throws Exception {
data.add(new Data(4, null, null, null, TABLE1, null, null, null, TRAN1, null));
data.add(new Data(5, null, null, null, TABLE1, null, null, null, TRAN2, null));

when(dataService.findDataGaps()).thenReturn(dataGaps);
ISqlRowMapper<Data> mapper = any();
when(sqlTemplate.queryForCursor((String) any(), mapper, (Object[]) any(), (int[]) any()))
.thenReturn(new ListReadCursor(data));

DataGapRouteReader dataGapRouteReader = buildReader(50, dataGaps);
dataGapRouteReader.execute();

BlockingQueue<Data> queue = dataGapRouteReader.getDataQueue();
Expand Down

0 comments on commit 268ccff

Please sign in to comment.