Skip to content

Commit

Permalink
[FFM-4023] - JavaSDK local connector doesn't create metrics folder (#162
Browse files Browse the repository at this point in the history
)

What
Fixes exception reported by LocalConnector when sub-folders are missing.

Why
LocalConnector needs flags, segments, metrics and a domain folder to exist before writing to them.

Testing
New unit test
  • Loading branch information
andybharness authored Sep 5, 2023
1 parent 16e6b41 commit 614faef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class LocalConnector implements Connector, AutoCloseable {

public LocalConnector(@NonNull final String source) {
this.source = source;
Stream.of("flags", "segments", "metrics")
.forEach(nextDir -> Paths.get(source, nextDir).toFile().mkdirs());
log.info("LocalConnector initialized with source {}", source);
}

Expand All @@ -55,6 +57,7 @@ protected Stream<File> listFiles(@NonNull final String source, @NonNull final St
throws ConnectorException {
log.debug("List files in {} with {}", source, domain);
try {
Paths.get(source, domain).toFile().mkdirs();
Stream<File> fileStream =
Files.list(Paths.get(source, domain))
.filter(Files::isRegularFile)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.harness.cf.client.connector;

import static org.junit.jupiter.api.Assertions.*;

import io.harness.cf.model.Metrics;
import java.util.ArrayList;
import org.junit.jupiter.api.Test;

class LocalConnectorTest {

@Test
void shouldNotThrowExceptionsIfFoldersDontExist() {
String source = "LocalConnectorTestSource";

Metrics metrics = new Metrics();
metrics.metricsData(new ArrayList<>());
metrics.targetData(new ArrayList<>());

assertDoesNotThrow(
() -> {
LocalConnector connector = new LocalConnector(source);
connector.listFiles(source, "domain");
connector.getFlags();
connector.getSegments();
connector.postMetrics(metrics);
});
}
}

0 comments on commit 614faef

Please sign in to comment.