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