Skip to content

Commit

Permalink
Fixed issue where reading exclusions from an external file was broken.
Browse files Browse the repository at this point in the history
  • Loading branch information
zegelin committed Feb 21, 2020
1 parent aa586b5 commit 3b88272
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<String> exclusionStrings = ImmutableSet.of("test_collector", "test:mbean=foo");
static Set<Harvester.Exclusion> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void setExclusions(final Set<String> 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);
Expand Down

0 comments on commit 3b88272

Please sign in to comment.