|
32 | 32 | import org.mockito.Mock;
|
33 | 33 |
|
34 | 34 | import com.datastax.cdm.cql.CommonMocks;
|
| 35 | +import com.datastax.cdm.feature.TrackRun; |
35 | 36 | import com.datastax.cdm.job.IJobSessionFactory.JobType;
|
36 | 37 | import com.datastax.cdm.job.PartitionRange;
|
37 | 38 | import com.datastax.cdm.job.RunNotStartedException;
|
@@ -72,15 +73,43 @@ public void setup() {
|
72 | 73 | }
|
73 | 74 |
|
74 | 75 | @Test
|
75 |
| - public void getPendingPartitions_nothingPending() throws RunNotStartedException { |
| 76 | + public void incorrectKsTable() { |
| 77 | + assertThrows(RuntimeException.class, () -> new TargetUpsertRunDetailsStatement(cqlSession, "table1")); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void getPendingPartitions_noPrevRun() throws RunNotStartedException { |
76 | 82 | targetUpsertRunDetailsStatement = new TargetUpsertRunDetailsStatement(cqlSession, "ks.table1");
|
77 | 83 | assertEquals(Collections.emptyList(), targetUpsertRunDetailsStatement.getPendingPartitions(0, JobType.MIGRATE));
|
78 |
| - assertEquals(Collections.emptyList(), targetUpsertRunDetailsStatement.getPendingPartitions(1, JobType.MIGRATE)); |
79 | 84 | }
|
80 | 85 |
|
81 | 86 | @Test
|
82 |
| - public void incorrectKsTable() throws RunNotStartedException { |
83 |
| - assertThrows(RuntimeException.class, () -> new TargetUpsertRunDetailsStatement(cqlSession, "table1")); |
| 87 | + public void getPendingPartitions_noPrevRunFound() { |
| 88 | + targetUpsertRunDetailsStatement = new TargetUpsertRunDetailsStatement(cqlSession, "ks.table1"); |
| 89 | + assertThrows(RunNotStartedException.class, |
| 90 | + () -> targetUpsertRunDetailsStatement.getPendingPartitions(1, JobType.MIGRATE)); |
| 91 | + } |
| 92 | + |
| 93 | + @Test |
| 94 | + public void getPendingPartitions_prevRunNotStarted() { |
| 95 | + when(rs.one()).thenReturn(row1); |
| 96 | + when(row1.getString("status")).thenReturn(TrackRun.RUN_STATUS.NOT_STARTED.toString()); |
| 97 | + |
| 98 | + targetUpsertRunDetailsStatement = new TargetUpsertRunDetailsStatement(cqlSession, "ks.table1"); |
| 99 | + assertThrows(RunNotStartedException.class, |
| 100 | + () -> targetUpsertRunDetailsStatement.getPendingPartitions(123, JobType.MIGRATE)); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void getPendingPartitions_prevRunNoPartsPending() throws RunNotStartedException { |
| 105 | + when(rs.one()).thenReturn(row1); |
| 106 | + when(row1.getString("status")).thenReturn(TrackRun.RUN_STATUS.ENDED.toString()); |
| 107 | + Iterator mockIterator = mock(Iterator.class); |
| 108 | + when(rs.iterator()).thenReturn(mockIterator); |
| 109 | + when(mockIterator.hasNext()).thenReturn(false); |
| 110 | + |
| 111 | + targetUpsertRunDetailsStatement = new TargetUpsertRunDetailsStatement(cqlSession, "ks.table1"); |
| 112 | + assertEquals(Collections.emptyList(), targetUpsertRunDetailsStatement.getPendingPartitions(123, JobType.MIGRATE)); |
84 | 113 | }
|
85 | 114 |
|
86 | 115 | @Test
|
|
0 commit comments