Skip to content

Commit 3ddb30f

Browse files
committed
Fixed issue where reading exclusions from an external file was broken.
1 parent bf9ac3a commit 3ddb30f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.zegelin.cassandra.exporter.cli;
2+
3+
import com.google.common.collect.ImmutableSet;
4+
import com.zegelin.cassandra.exporter.Harvester;
5+
import org.testng.annotations.Test;
6+
7+
import java.io.IOException;
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.util.Set;
11+
import java.util.stream.Collectors;
12+
13+
import static org.testng.Assert.*;
14+
15+
public class HarvesterOptionsTest {
16+
17+
static Set<String> exclusionStrings = ImmutableSet.of("test_collector", "test:mbean=foo");
18+
static Set<Harvester.Exclusion> exclusions = exclusionStrings.stream()
19+
.map(Harvester.Exclusion::create)
20+
.collect(Collectors.toSet());
21+
22+
@org.testng.annotations.Test
23+
public void testSetExclusions() {
24+
final HarvesterOptions harvesterOptions = new HarvesterOptions();
25+
26+
harvesterOptions.setExclusions(exclusionStrings);
27+
28+
assertEquals(harvesterOptions.exclusions, exclusions);
29+
}
30+
31+
@Test
32+
public void testSetExclusionsFromFile() throws IOException {
33+
final Path tempFile = Files.createTempFile(null, null);
34+
35+
Files.write(tempFile, exclusionStrings);
36+
37+
final HarvesterOptions harvesterOptions = new HarvesterOptions();
38+
39+
harvesterOptions.setExclusions(ImmutableSet.of(String.format("@%s", tempFile)));
40+
41+
assertEquals(harvesterOptions.exclusions, exclusions);
42+
}
43+
}

common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void setExclusions(final Set<String> values) {
4646
Files.lines(file)
4747
.filter(line -> !line.startsWith("#"))
4848
.map(String::trim)
49-
.filter(String::isEmpty)
49+
.filter(line -> !line.isEmpty())
5050
.forEach(line -> this.exclusions.add(Harvester.Exclusion.create(line)));
5151

5252
processedExclusionFiles.add(file);

0 commit comments

Comments
 (0)