Skip to content

Commit

Permalink
test: Fixed RIOT File tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Jul 30, 2022
1 parent 46b3c23 commit 6143c68
Show file tree
Hide file tree
Showing 6 changed files with 3,264 additions and 7,222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
@SuppressWarnings("unchecked")
class FileIntegrationTests extends AbstractRiotIntegrationTests {

protected final static int COUNT = 2410;
public static final String BEERS_JSON_URL = "https://storage.googleapis.com/jrx/beers.json";
public static final int BEER_CSV_COUNT = 2410;
public static final int BEER_JSON_COUNT = 216;

private static Path tempDir;

Expand Down Expand Up @@ -118,7 +120,7 @@ void importCSV(RedisTestContext redis) throws Exception {
execute("import-csv", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(COUNT, keys.size());
Assertions.assertEquals(BEER_CSV_COUNT, keys.size());
}

@ParameterizedTest
Expand Down Expand Up @@ -198,27 +200,27 @@ void importGlob(RedisTestContext redis) throws Exception {
execute("import-glob", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(COUNT, keys.size());
Assertions.assertEquals(BEER_CSV_COUNT, keys.size());
}

@ParameterizedTest
@RedisTestContextsSource
void importGeoadd(RedisTestContext redis) throws Exception {
execute("import-geoadd", redis);
RedisGeoCommands<String, String> sync = redis.sync();
Set<String> results = sync.georadius("airportgeo", -122.4194, 37.7749, 20, GeoArgs.Unit.mi);
Assertions.assertTrue(results.contains("3469"));
Assertions.assertTrue(results.contains("10360"));
Assertions.assertTrue(results.contains("8982"));
Set<String> results = sync.georadius("airportgeo", -21, 64, 200, GeoArgs.Unit.mi);
Assertions.assertTrue(results.contains("18"));
Assertions.assertTrue(results.contains("19"));
Assertions.assertTrue(results.contains("11"));
}

@ParameterizedTest
@RedisTestContextsSource
void importGeoProcessor(RedisTestContext redis) throws Exception {
execute("import-geo-processor", redis);
RedisHashCommands<String, String> sync = redis.sync();
Map<String, String> airport3469 = sync.hgetall("airport:3469");
Assertions.assertEquals("-122.375,37.61899948120117", airport3469.get("location"));
Map<String, String> airport3469 = sync.hgetall("airport:18");
Assertions.assertEquals("-21.9405994415,64.1299972534", airport3469.get("location"));
}

@ParameterizedTest
Expand All @@ -242,7 +244,7 @@ void importProcessElvis(RedisTestContext redis) throws Exception {
execute("import-process-elvis", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(COUNT, keys.size());
Assertions.assertEquals(BEER_CSV_COUNT, keys.size());
Map<String, String> beer1436 = ((RedisHashCommands<String, String>) sync).hgetall("beer:1436");
Assertions.assertEquals("10", beer1436.get("ibu"));
}
Expand All @@ -253,7 +255,7 @@ void importMultiCommands(RedisTestContext redis) throws Exception {
execute("import-multi-commands", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> beers = sync.keys("beer:*");
Assertions.assertEquals(2410, beers.size());
Assertions.assertEquals(BEER_CSV_COUNT, beers.size());
for (String beer : beers) {
Map<String, String> hash = ((RedisHashCommands<String, String>) sync).hgetall(beer);
Assertions.assertTrue(hash.containsKey("name"));
Expand Down Expand Up @@ -330,7 +332,7 @@ void importJSON(RedisTestContext redis) throws Exception {
execute("import-json", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(4432, keys.size());
Assertions.assertEquals(BEER_JSON_COUNT, keys.size());
Map<String, String> beer1 = ((RedisHashCommands<String, String>) sync).hgetall("beer:1");
Assertions.assertEquals("Hocus Pocus", beer1.get("name"));
}
Expand Down Expand Up @@ -428,7 +430,7 @@ void exportXml(RedisTestContext redis) throws Exception {
void importJsonAPI(RedisTestContext redis) throws Exception {
// riot-file import hset --keyspace beer --keys id
FileImportCommand command = new FileImportCommand();
command.setFiles(Collections.singletonList("https://storage.googleapis.com/jrx/beers.json"));
command.setFiles(Collections.singletonList(BEERS_JSON_URL));
HsetCommand hset = new HsetCommand();
hset.setKeyspace("beer");
hset.setKeys(new String[] { "id" });
Expand All @@ -439,7 +441,7 @@ void importJsonAPI(RedisTestContext redis) throws Exception {
command.call();
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(4432, keys.size());
Assertions.assertEquals(BEER_JSON_COUNT, keys.size());
Map<String, String> beer1 = ((RedisHashCommands<String, String>) sync).hgetall("beer:1");
Assertions.assertEquals("Hocus Pocus", beer1.get("name"));
}
Expand All @@ -450,7 +452,7 @@ void importJSONGzip(RedisTestContext redis) throws Exception {
execute("import-json-gz", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Assertions.assertEquals(30409, keys.size());
Assertions.assertEquals(BEER_JSON_COUNT, keys.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FileTests {
@Test
void importJSON() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
FileImportCommand command = FileImportCommand.builder().build();
Iterator<Map<String, Object>> iterator = command.read("https://storage.googleapis.com/jrx/beers.json");
Iterator<Map<String, Object>> iterator = command.read(FileIntegrationTests.BEERS_JSON_URL);
Assertions.assertTrue(iterator.hasNext());
Map<String, Object> beer1 = iterator.next();
Assertions.assertEquals(13, beer1.size());
Expand All @@ -23,7 +23,7 @@ void importJSON() throws UnexpectedInputException, ParseException, NonTransientR
iterator.next();
count++;
}
Assertions.assertEquals(4432, count);
Assertions.assertEquals(FileIntegrationTests.BEER_JSON_COUNT, count);
}

@Test
Expand All @@ -39,7 +39,7 @@ void importCSV() throws UnexpectedInputException, ParseException, NonTransientRe
iterator.next();
count++;
}
Assertions.assertEquals(2410, count);
Assertions.assertEquals(FileIntegrationTests.BEER_CSV_COUNT, count);
}

}
Loading

0 comments on commit 6143c68

Please sign in to comment.