mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2024-11-25 18:20:33 -06:00
NBIO list api test fixes
This commit is contained in:
parent
20cb7fdae7
commit
510a9dd354
@ -238,20 +238,16 @@ public class NBIO implements NBPathsAPI.Facets {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Optional<Content<?>>> resolveEach() {
|
||||
List<Optional<Content<?>>> resolved = new ArrayList<>();
|
||||
public List<List<Content<?>>> resolveEach() {
|
||||
List<List<Content<?>>> resolved = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
LinkedHashSet<String> slotSearchPaths = expandSearches(prefixes, List.of(name), extensions, false);
|
||||
Content<?> content = null;
|
||||
for (String slotSearchPath : slotSearchPaths) {
|
||||
content = resolver.resolve(slotSearchPath);
|
||||
if (content != null) {
|
||||
break;
|
||||
}
|
||||
List<Content<?>> contents = resolver.resolve(slotSearchPath);
|
||||
resolved.add(contents);
|
||||
}
|
||||
resolved.add(Optional.ofNullable(content));
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
@ -336,27 +332,20 @@ public class NBIO implements NBPathsAPI.Facets {
|
||||
|
||||
// wrap in local search iterator
|
||||
for (String search : searches) {
|
||||
Content<?> foundInLocal = resolver.resolve(search);
|
||||
if (foundInLocal != null) {
|
||||
foundFiles.add(foundInLocal);
|
||||
}
|
||||
List<Content<?>> founds = resolver.resolve(search);
|
||||
foundFiles.addAll(founds);
|
||||
}
|
||||
|
||||
for (String searchPath : prefixes) {
|
||||
Optional<Path> opath = resolver.resolveDirectory(searchPath);
|
||||
Path path = opath.orElseThrow();
|
||||
|
||||
List<Path> founds = resolver.resolveDirectory(searchPath);
|
||||
FileCapture capture = new FileCapture();
|
||||
for (String searchPattern : searches) {
|
||||
RegexPathFilter filter = new RegexPathFilter(searchPattern, true);
|
||||
NBIOWalker.walkFullPath(path, capture, filter);
|
||||
}
|
||||
|
||||
for (Path foundPath : capture) {
|
||||
// Path fullPath = path.resolve(foundPath);
|
||||
// foundFiles.add(new PathContent(fullPath));
|
||||
foundFiles.add(new PathContent(foundPath));
|
||||
for (Path path : founds) {
|
||||
for (String searchPattern : searches) {
|
||||
RegexPathFilter filter = new RegexPathFilter(searchPattern, true);
|
||||
NBIOWalker.walkFullPath(path, capture, filter);
|
||||
}
|
||||
}
|
||||
capture.found.stream().map(PathContent::new).forEach(foundFiles::add);
|
||||
}
|
||||
|
||||
return new ArrayList<>(foundFiles);
|
||||
|
@ -21,7 +21,7 @@ public class ResolverForURL implements ContentResolver {
|
||||
@Override
|
||||
public List<Content<?>> resolve(URI uri) {
|
||||
if (uri.getScheme()==null) {
|
||||
return null;
|
||||
return List.of();
|
||||
}
|
||||
if (uri.getScheme().equals("http")
|
||||
|| uri.getScheme().equals("https")) {
|
||||
@ -34,8 +34,7 @@ public class ResolverForURL implements ContentResolver {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return List.of(); }
|
||||
|
||||
@Override
|
||||
public List<Path> resolveDirectory(URI uri) {
|
||||
|
@ -84,7 +84,8 @@ public class URIResolver implements ContentResolver {
|
||||
public List<Content<?>> resolve(URI uri) {
|
||||
List<Content<?>> resolved = new ArrayList<>();
|
||||
for (ContentResolver loader : loaders) {
|
||||
resolved.addAll(loader.resolve(uri));
|
||||
List<Content<?>> contents = loader.resolve(uri);
|
||||
resolved.addAll(contents);
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public interface NBPathsAPI {
|
||||
* of {@link #first()}, except that it returns a result pair-wise for each name given.
|
||||
* @return A list of optional {@code Content<?>} elements.
|
||||
*/
|
||||
List<Optional<Content<?>>> resolveEach();
|
||||
List<List<Content<?>>> resolveEach();
|
||||
|
||||
List<Content<?>> list();
|
||||
|
||||
|
@ -91,10 +91,10 @@ public class NBIOTest {
|
||||
|
||||
@Test
|
||||
public void testClasspathTestResource() {
|
||||
List<Optional<Content<?>>> optionals =
|
||||
List<List<Content<?>>> optionals =
|
||||
NBIO.classpath().name("nesteddir1/nesteddir2/testcsv12.csv").resolveEach();
|
||||
assertThat(optionals).hasSize(1);
|
||||
Content<?> content = optionals.get(0).get();
|
||||
Content<?> content = optionals.get(0).get(0);
|
||||
assertThat(content).isNotNull();
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -16,9 +17,9 @@ public class ResolverForURLTest {
|
||||
@Test
|
||||
public void testUrlResource() {
|
||||
ResolverForURL r = new ResolverForURL();
|
||||
Content<?> c = r.resolve("http://google.com");
|
||||
List<Content<?>> c = r.resolve("http://google.com");
|
||||
assertThat(c).isNotNull();
|
||||
Object location = c.getLocation();
|
||||
Object location = c.get(0).getLocation();
|
||||
assertThat(location).isInstanceOf(URL.class);
|
||||
assertThat(location.toString()).isEqualTo("http://google.com");
|
||||
}
|
||||
@ -27,15 +28,15 @@ public class ResolverForURLTest {
|
||||
public void testFileResource() {
|
||||
String p = "src/test/resources/nesteddir1/nesteddir2/testcsv12.csv";
|
||||
ResolverForFilesystem r = new ResolverForFilesystem();
|
||||
Content<?> c = r.resolve(p);
|
||||
List<Content<?>> c = r.resolve(p);
|
||||
assertThat(c).isNotNull();
|
||||
Object location = c.getLocation();
|
||||
Object location = c.get(0).getLocation();
|
||||
assertThat(location).isInstanceOf(Path.class);
|
||||
assertThat(location.toString()).isEqualTo(p);
|
||||
|
||||
String q = "nesteddir1/nesteddir2/testcsv12.csv";
|
||||
Content<?> notfound = r.resolve(q);
|
||||
assertThat(notfound).isNull();
|
||||
List<Content<?>> notfound = r.resolve(q);
|
||||
assertThat(notfound).isEmpty();
|
||||
|
||||
}
|
||||
|
||||
@ -44,14 +45,14 @@ public class ResolverForURLTest {
|
||||
String cprootForTestContext = "target/test-classes/";
|
||||
String resourcePathWithinClasspathRoots = "nesteddir1/nesteddir2/testcsv12.csv";
|
||||
ResolverForClasspath r = new ResolverForClasspath();
|
||||
Content<?> c = r.resolve(resourcePathWithinClasspathRoots);
|
||||
List<Content<?>> c = r.resolve(resourcePathWithinClasspathRoots);
|
||||
assertThat(c).isNotNull();
|
||||
Object location = c.getLocation();
|
||||
Object location = c.get(0).getLocation();
|
||||
assertThat(location.toString()).isEqualTo(cprootForTestContext + resourcePathWithinClasspathRoots);
|
||||
|
||||
String q = "src/test/resources/nesteddir1/nesteddir2/testcsv12.csv";
|
||||
Content<?> notfound = r.resolve(q);
|
||||
assertThat(notfound).isNull();
|
||||
List<Content<?>> notfound = r.resolve(q);
|
||||
assertThat(notfound).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -72,6 +72,9 @@ public class CSVFrequencySampler implements LongFunction<String> {
|
||||
Set<String> values = new HashSet<>();
|
||||
List<EvProbD> frequencies = new ArrayList<>();
|
||||
|
||||
if (!filename.endsWith(".csv")) {
|
||||
filename = filename + ".csv";
|
||||
}
|
||||
CSVParser csvdata = NBIO.readFileCSV(filename);
|
||||
Frequency freq = new Frequency();
|
||||
for (CSVRecord csvdatum : csvdata) {
|
||||
|
@ -75,6 +75,9 @@ public class DelimFrequencySampler implements LongFunction<String> {
|
||||
Set<String> values = new HashSet<>();
|
||||
List<EvProbD> frequencies = new ArrayList<>();
|
||||
|
||||
if (!filename.endsWith(".csv")) {
|
||||
filename = filename + ".csv";
|
||||
}
|
||||
CSVParser csvdata = NBIO.readFileDelimCSV(filename,delimiter);
|
||||
Frequency freq = new Frequency();
|
||||
for (CSVRecord csvdatum : csvdata) {
|
||||
|
@ -71,6 +71,9 @@ public class WeightedStringsFromCSV implements LongFunction<String> {
|
||||
this.hash=new Hash();
|
||||
}
|
||||
for (String filename: filenames) {
|
||||
if (!filename.endsWith(".csv")) {
|
||||
filename = filename+".csv";
|
||||
}
|
||||
CSVParser csvdata = NBIO.readFileCSV(filename);
|
||||
for (CSVRecord csvdatum : csvdata) {
|
||||
String value = csvdatum.get(valueColumn);
|
||||
|
Loading…
Reference in New Issue
Block a user