diff --git a/agent/src/test/java/com/zegelin/cassandra/exporter/cli/HarvesterOptionsTest.java b/agent/src/test/java/com/zegelin/cassandra/exporter/cli/HarvesterOptionsTest.java new file mode 100644 index 0000000..ba2cb59 --- /dev/null +++ b/agent/src/test/java/com/zegelin/cassandra/exporter/cli/HarvesterOptionsTest.java @@ -0,0 +1,43 @@ +package com.zegelin.cassandra.exporter.cli; + +import com.google.common.collect.ImmutableSet; +import com.zegelin.cassandra.exporter.Harvester; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.testng.Assert.*; + +public class HarvesterOptionsTest { + + static Set exclusionStrings = ImmutableSet.of("test_collector", "test:mbean=foo"); + static Set exclusions = exclusionStrings.stream() + .map(Harvester.Exclusion::create) + .collect(Collectors.toSet()); + + @org.testng.annotations.Test + public void testSetExclusions() { + final HarvesterOptions harvesterOptions = new HarvesterOptions(); + + harvesterOptions.setExclusions(exclusionStrings); + + assertEquals(harvesterOptions.exclusions, exclusions); + } + + @Test + public void testSetExclusionsFromFile() throws IOException { + final Path tempFile = Files.createTempFile(null, null); + + Files.write(tempFile, exclusionStrings); + + final HarvesterOptions harvesterOptions = new HarvesterOptions(); + + harvesterOptions.setExclusions(ImmutableSet.of(String.format("@%s", tempFile))); + + assertEquals(harvesterOptions.exclusions, exclusions); + } +} \ No newline at end of file diff --git a/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java b/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java index 580b0e4..dea9e82 100644 --- a/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java +++ b/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java @@ -46,7 +46,7 @@ void setExclusions(final Set values) { Files.lines(file) .filter(line -> !line.startsWith("#")) .map(String::trim) - .filter(String::isEmpty) + .filter(line -> !line.isEmpty()) .forEach(line -> this.exclusions.add(Harvester.Exclusion.create(line))); processedExclusionFiles.add(file);