Skip to content

Commit b9b5e39

Browse files
authored
Feature/fix code coverage issue (#228)
* Fixed coverage issue * Fixed mockito version * Minor coverage updates & enabled back scala
1 parent 73401b9 commit b9b5e39

File tree

5 files changed

+70
-63
lines changed

5 files changed

+70
-63
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Migrate and Validate Tables between Origin and Target Cassandra Clusters.
1818

1919
### Prerequisite
2020
- Install Java8 as spark binaries are compiled with it.
21-
- Install Spark version [3.4.1](https://archive.apache.org/dist/spark/spark-3.4.1/) on a single VM (no cluster necessary) where you want to run this job. Spark can be installed by running the following: -
21+
- Install Spark version [3.4.1](https://archive.apache.org/dist/spark/spark-3.4.1/spark-3.4.1-bin-hadoop3-scala2.13.tgz) on a single VM (no cluster necessary) where you want to run this job. Spark can be installed by running the following: -
2222
```
2323
wget https://archive.apache.org/dist/spark/spark-3.4.1/spark-3.4.1-bin-hadoop3-scala2.13.tgz
2424
tar -xvzf spark-3.4.1-bin-hadoop3-scala2.13.tgz
@@ -97,7 +97,7 @@ Each line above represents a partition-range (`min,max`). Alternatively, you can
9797
./spark-submit --properties-file cdm.properties \
9898
--conf spark.cdm.schema.origin.keyspaceTable="<keyspacename>.<tablename>" \
9999
--conf spark.cdm.tokenRange.partitionFile="/<path-to-file>/<csv-input-filename>" \
100-
--master "local[*]" --driver-memory 25G --executor-memory 25G \
100+
--master "local[*]" --driver-memory 25G --executor-memory 25G \
101101
--class com.datastax.cdm.job.<Migrate|DiffData> cassandra-data-migrator-4.x.x.jar &> logfile_name_$(date +%Y%m%d_%H_%M).txt
102102
```
103103
This mode is specifically useful to processes a subset of partition-ranges that may have failed during a previous run.

RELEASE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Release Notes
2+
## [4.1.9 to 4.1.11] - 2023-12-11
3+
- Code test & coverage changes
4+
25
## [4.1.8] - 2023-10-13
36
- Upgraded to use Scala 2.13
47

pom.xml

Lines changed: 24 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33

44
<groupId>datastax.cdm</groupId>
55
<artifactId>cassandra-data-migrator</artifactId>
6-
<version>4.1.10-SNAPSHOT</version>
6+
<version>4.1.11-SNAPSHOT</version>
77
<packaging>jar</packaging>
88

99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1111
<scala.version>2.13.12</scala.version>
1212
<scala.main.version>2.13</scala.main.version>
1313
<spark.version>3.4.1</spark.version>
14-
<scalatest.version>3.2.17</scalatest.version>
1514
<connector.version>3.4.1</connector.version>
1615
<cassandra.version>5.0-alpha1</cassandra.version>
1716
<junit.version>5.9.1</junit.version>
@@ -151,12 +150,6 @@
151150
</dependency>
152151

153152
<!-- Test Dependencies -->
154-
<dependency>
155-
<groupId>org.scalatest</groupId>
156-
<artifactId>scalatest_${scala.main.version}</artifactId>
157-
<version>${scalatest.version}</version>
158-
<scope>test</scope>
159-
</dependency>
160153
<dependency>
161154
<groupId>org.junit.jupiter</groupId>
162155
<artifactId>junit-jupiter-engine</artifactId>
@@ -200,20 +193,27 @@
200193
</resources>
201194
<plugins>
202195
<plugin>
203-
<groupId>net.alchim31.maven</groupId>
204-
<artifactId>scala-maven-plugin</artifactId>
205-
<version>4.8.0</version>
206-
<executions>
207-
<execution>
208-
<phase>process-sources</phase>
209-
<goals>
210-
<goal>compile</goal>
211-
<goal>testCompile</goal>
212-
</goals>
196+
<groupId>net.alchim31.maven</groupId>
197+
<artifactId>scala-maven-plugin</artifactId>
198+
<version>4.8.0</version>
199+
<executions>
200+
<execution>
201+
<phase>process-sources</phase>
202+
<goals>
203+
<goal>compile</goal>
204+
<goal>testCompile</goal>
205+
</goals>
213206

214-
</execution>
215-
</executions>
207+
</execution>
208+
</executions>
216209
</plugin>
210+
211+
<plugin>
212+
<groupId>org.apache.maven.plugins</groupId>
213+
<artifactId>maven-surefire-plugin</artifactId>
214+
<version>2.22.2</version>
215+
</plugin>
216+
217217
<plugin>
218218
<groupId>org.apache.maven.plugins</groupId>
219219
<artifactId>maven-shade-plugin</artifactId>
@@ -242,35 +242,6 @@
242242
</execution>
243243
</executions>
244244
</plugin>
245-
<!-- Instructions from http://www.scalatest.org/user_guide/using_the_scalatest_maven_plugin -->
246-
<!-- disable surefire -->
247-
<plugin>
248-
<groupId>org.apache.maven.plugins</groupId>
249-
<artifactId>maven-surefire-plugin</artifactId>
250-
<version>2.22.2</version>
251-
<configuration>
252-
<skipTests>true</skipTests>
253-
</configuration>
254-
</plugin>
255-
<!-- enable scalatest -->
256-
<plugin>
257-
<groupId>org.scalatest</groupId>
258-
<artifactId>scalatest-maven-plugin</artifactId>
259-
<version>2.2.0</version>
260-
<configuration>
261-
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
262-
<junitxml>.</junitxml>
263-
<filereports>WDF TestSuite.txt</filereports>
264-
</configuration>
265-
<executions>
266-
<execution>
267-
<id>test</id>
268-
<goals>
269-
<goal>test</goal>
270-
</goals>
271-
</execution>
272-
</executions>
273-
</plugin>
274245

275246
<plugin>
276247
<groupId>org.apache.maven.plugins</groupId>
@@ -304,35 +275,28 @@
304275
<id>jacoco-check</id>
305276
<phase>test</phase>
306277
<goals>
307-
<goal>check</goal>
308278
<goal>report</goal>
279+
<goal>check</goal>
309280
</goals>
310281
<configuration>
311-
<excludes>
312-
<!-- Excluding all the Scala classes -->
313-
<exclude>com.datastax.cdm.job.*</exclude>
314-
</excludes>
315282
<rules>
316283
<rule>
317284
<element>BUNDLE</element>
318285
<limits>
319286
<limit>
320287
<counter>COMPLEXITY</counter>
321288
<value>COVEREDRATIO</value>
322-
<!-- <minimum>0.33</minimum>-->
323-
<minimum>0</minimum>
289+
<minimum>0.33</minimum>
324290
</limit>
325291
<limit>
326292
<counter>INSTRUCTION</counter>
327293
<value>COVEREDRATIO</value>
328-
<!-- <minimum>41%</minimum>-->
329-
<minimum>0%</minimum>
294+
<minimum>45%</minimum>
330295
</limit>
331296
<limit>
332297
<counter>LINE</counter>
333298
<value>MISSEDCOUNT</value>
334-
<!-- <maximum>1544</maximum>-->
335-
<maximum>3085</maximum>
299+
<maximum>1500</maximum>
336300
</limit>
337301
</limits>
338302
</rule>

src/main/java/com/datastax/cdm/job/SplitPartitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class SplitPartitions {
3535

3636
public static Logger logger = LoggerFactory.getLogger(SplitPartitions.class.getName());
3737

38-
public static Collection<Partition> getRandomSubPartitions(int numSplits, BigInteger min, BigInteger max, int coveragePercent) {
38+
public static List<Partition> getRandomSubPartitions(int numSplits, BigInteger min, BigInteger max, int coveragePercent) {
3939
logger.info("ThreadID: {} Splitting min: {} max: {}", Thread.currentThread().getId(), min, max);
4040
List<Partition> partitions = getSubPartitions(numSplits, min, max, coveragePercent);
4141
Collections.shuffle(partitions);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.datastax.cdm.job;
2+
3+
import org.junit.jupiter.api.AfterEach;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.math.BigInteger;
8+
import java.util.Arrays;
9+
import java.util.Collection;
10+
import java.util.List;
11+
import java.util.stream.Stream;
12+
13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
15+
public class SplitPartitionsTest {
16+
17+
@Test
18+
void getRandomSubPartitionsTest() {
19+
List<SplitPartitions.Partition> partitions = SplitPartitions.getRandomSubPartitions(10, BigInteger.ONE,
20+
BigInteger.valueOf(100), 100);
21+
assertEquals(10, partitions.size());
22+
partitions.forEach(p -> {
23+
assertEquals(9, p.getMax().longValue() - p.getMin().longValue());
24+
});
25+
}
26+
27+
@Test
28+
void getRandomSubPartitionsTestOver100() {
29+
List<SplitPartitions.Partition> partitions = SplitPartitions.getRandomSubPartitions(8, BigInteger.ONE,
30+
BigInteger.valueOf(44), 200);
31+
assertEquals(8, partitions.size());
32+
}
33+
@Test
34+
void batchesTest() {
35+
List<String> mutable_list = Arrays.asList("e1", "e2", "e3", "e4", "e5", "e6");
36+
Stream<List<String>> out = SplitPartitions.batches(mutable_list, 2);
37+
assertEquals(3, out.count());
38+
}
39+
40+
}

0 commit comments

Comments
 (0)