test(javaTest): freeze complete WCS grid snapshot
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
package com.ft546.wcs.shadow.history;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public final class HistoricalMapCell {
|
||||||
|
private final String siteId;
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int z;
|
||||||
|
private final int value;
|
||||||
|
private final String axy;
|
||||||
|
private final String warehouse;
|
||||||
|
private final String spaceArea;
|
||||||
|
|
||||||
|
@JsonCreator
|
||||||
|
public HistoricalMapCell(@JsonProperty("site_id") String siteId,
|
||||||
|
@JsonProperty("x") int x,
|
||||||
|
@JsonProperty("y") int y,
|
||||||
|
@JsonProperty("z") int z,
|
||||||
|
@JsonProperty("value") int value,
|
||||||
|
@JsonProperty("axy") String axy,
|
||||||
|
@JsonProperty("warehouse") String warehouse,
|
||||||
|
@JsonProperty("space_area") String spaceArea) {
|
||||||
|
this.siteId = siteId == null ? "" : siteId;
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.value = value;
|
||||||
|
this.axy = axy == null ? "" : axy;
|
||||||
|
this.warehouse = warehouse == null ? "" : warehouse;
|
||||||
|
this.spaceArea = spaceArea == null ? "" : spaceArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSiteId() { return siteId; }
|
||||||
|
public int getX() { return x; }
|
||||||
|
public int getY() { return y; }
|
||||||
|
public int getZ() { return z; }
|
||||||
|
public int getValue() { return value; }
|
||||||
|
public String getAxy() { return axy; }
|
||||||
|
public String getWarehouse() { return warehouse; }
|
||||||
|
public String getSpaceArea() { return spaceArea; }
|
||||||
|
}
|
||||||
@@ -11,6 +11,9 @@ import java.util.Set;
|
|||||||
public final class HistoricalQueueDataset {
|
public final class HistoricalQueueDataset {
|
||||||
private final List<HistoricalQueueRecord> records;
|
private final List<HistoricalQueueRecord> records;
|
||||||
private final Map<String, HistoricalMapSite> mapSiteDetails;
|
private final Map<String, HistoricalMapSite> mapSiteDetails;
|
||||||
|
private final List<HistoricalMapCell> fullMapCells;
|
||||||
|
private final int fullMapRows;
|
||||||
|
private final String fullMapSha256;
|
||||||
private final int manifestSampleRows;
|
private final int manifestSampleRows;
|
||||||
private final int fullScanTotalRows;
|
private final int fullScanTotalRows;
|
||||||
private final String database;
|
private final String database;
|
||||||
@@ -26,6 +29,8 @@ public final class HistoricalQueueDataset {
|
|||||||
|
|
||||||
public HistoricalQueueDataset(List<HistoricalQueueRecord> records,
|
public HistoricalQueueDataset(List<HistoricalQueueRecord> records,
|
||||||
Map<String, HistoricalMapSite> mapSiteDetails,
|
Map<String, HistoricalMapSite> mapSiteDetails,
|
||||||
|
List<HistoricalMapCell> fullMapCells,
|
||||||
|
int fullMapRows, String fullMapSha256,
|
||||||
int manifestSampleRows, int fullScanTotalRows,
|
int manifestSampleRows, int fullScanTotalRows,
|
||||||
String database, String sourceTable, String extractedAt,
|
String database, String sourceTable, String extractedAt,
|
||||||
String minCreateDate, String maxCreateDate,
|
String minCreateDate, String maxCreateDate,
|
||||||
@@ -35,6 +40,10 @@ public final class HistoricalQueueDataset {
|
|||||||
this.records = Collections.unmodifiableList(new ArrayList<HistoricalQueueRecord>(records));
|
this.records = Collections.unmodifiableList(new ArrayList<HistoricalQueueRecord>(records));
|
||||||
this.mapSiteDetails = Collections.unmodifiableMap(
|
this.mapSiteDetails = Collections.unmodifiableMap(
|
||||||
new LinkedHashMap<String, HistoricalMapSite>(mapSiteDetails));
|
new LinkedHashMap<String, HistoricalMapSite>(mapSiteDetails));
|
||||||
|
this.fullMapCells = Collections.unmodifiableList(
|
||||||
|
new ArrayList<HistoricalMapCell>(fullMapCells));
|
||||||
|
this.fullMapRows = fullMapRows;
|
||||||
|
this.fullMapSha256 = fullMapSha256;
|
||||||
this.manifestSampleRows = manifestSampleRows;
|
this.manifestSampleRows = manifestSampleRows;
|
||||||
this.fullScanTotalRows = fullScanTotalRows;
|
this.fullScanTotalRows = fullScanTotalRows;
|
||||||
this.database = database;
|
this.database = database;
|
||||||
@@ -55,6 +64,9 @@ public final class HistoricalQueueDataset {
|
|||||||
new LinkedHashSet<String>(mapSiteDetails.keySet()));
|
new LinkedHashSet<String>(mapSiteDetails.keySet()));
|
||||||
}
|
}
|
||||||
public Map<String, HistoricalMapSite> getMapSiteDetails() { return mapSiteDetails; }
|
public Map<String, HistoricalMapSite> getMapSiteDetails() { return mapSiteDetails; }
|
||||||
|
public List<HistoricalMapCell> getFullMapCells() { return fullMapCells; }
|
||||||
|
public int getFullMapRows() { return fullMapRows; }
|
||||||
|
public String getFullMapSha256() { return fullMapSha256; }
|
||||||
public int getManifestSampleRows() { return manifestSampleRows; }
|
public int getManifestSampleRows() { return manifestSampleRows; }
|
||||||
public int getFullScanTotalRows() { return fullScanTotalRows; }
|
public int getFullScanTotalRows() { return fullScanTotalRows; }
|
||||||
public String getDatabase() { return database; }
|
public String getDatabase() { return database; }
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import java.net.URLClassLoader;
|
|||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public final class HistoricalQueueLoader {
|
public final class HistoricalQueueLoader {
|
||||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||||
@@ -29,12 +31,23 @@ public final class HistoricalQueueLoader {
|
|||||||
byte[] queueBytes = read(loader, basePath + "/queue-history-200.json");
|
byte[] queueBytes = read(loader, basePath + "/queue-history-200.json");
|
||||||
byte[] mapBytes = read(loader, basePath + "/map-sites.json");
|
byte[] mapBytes = read(loader, basePath + "/map-sites.json");
|
||||||
byte[] summaryBytes = read(loader, basePath + "/full-scan-summary.json");
|
byte[] summaryBytes = read(loader, basePath + "/full-scan-summary.json");
|
||||||
|
byte[] fullMapBytes = read(loader, basePath + "/full-map-grid.json");
|
||||||
verifySha256(manifest.path("sha256").path("queue-history-200.json").asText(), queueBytes);
|
verifySha256(manifest.path("sha256").path("queue-history-200.json").asText(), queueBytes);
|
||||||
verifySha256(manifest.path("sha256").path("map-sites.json").asText(), mapBytes);
|
verifySha256(manifest.path("sha256").path("map-sites.json").asText(), mapBytes);
|
||||||
verifySha256(manifest.path("sha256").path("full-scan-summary.json").asText(), summaryBytes);
|
verifySha256(manifest.path("sha256").path("full-scan-summary.json").asText(), summaryBytes);
|
||||||
|
String fullMapSha256 = manifest.path("sha256").path("full-map-grid.json").asText();
|
||||||
|
verifySha256(fullMapSha256, fullMapBytes);
|
||||||
CollectionType rowsType = MAPPER.getTypeFactory()
|
CollectionType rowsType = MAPPER.getTypeFactory()
|
||||||
.constructCollectionType(List.class, HistoricalQueueRecord.class);
|
.constructCollectionType(List.class, HistoricalQueueRecord.class);
|
||||||
List<HistoricalQueueRecord> rows = MAPPER.readValue(queueBytes, rowsType);
|
List<HistoricalQueueRecord> rows = MAPPER.readValue(queueBytes, rowsType);
|
||||||
|
CollectionType cellsType = MAPPER.getTypeFactory()
|
||||||
|
.constructCollectionType(List.class, HistoricalMapCell.class);
|
||||||
|
List<HistoricalMapCell> fullMapCells = MAPPER.readValue(fullMapBytes, cellsType);
|
||||||
|
int fullMapRows = manifest.path("fullMapRows").asInt();
|
||||||
|
if (fullMapRows != fullMapCells.size()) {
|
||||||
|
throw new IllegalArgumentException("full map row count mismatch");
|
||||||
|
}
|
||||||
|
validatePassableCells(fullMapCells);
|
||||||
Map<String, HistoricalMapSite> sites =
|
Map<String, HistoricalMapSite> sites =
|
||||||
new LinkedHashMap<String, HistoricalMapSite>();
|
new LinkedHashMap<String, HistoricalMapSite>();
|
||||||
for (JsonNode node : MAPPER.readTree(mapBytes)) {
|
for (JsonNode node : MAPPER.readTree(mapBytes)) {
|
||||||
@@ -61,7 +74,8 @@ public final class HistoricalQueueLoader {
|
|||||||
if (totalRows != manifest.path("totalRows").asInt()) {
|
if (totalRows != manifest.path("totalRows").asInt()) {
|
||||||
throw new IllegalArgumentException("history full scan row count mismatch");
|
throw new IllegalArgumentException("history full scan row count mismatch");
|
||||||
}
|
}
|
||||||
return new HistoricalQueueDataset(rows, sites, sampleRows, totalRows,
|
return new HistoricalQueueDataset(rows, sites, fullMapCells,
|
||||||
|
fullMapRows, fullMapSha256, sampleRows, totalRows,
|
||||||
manifest.path("database").asText(), manifest.path("table").asText(),
|
manifest.path("database").asText(), manifest.path("table").asText(),
|
||||||
manifest.path("extractedAt").asText(),
|
manifest.path("extractedAt").asText(),
|
||||||
scanSummary.path("min_create_date").asText(),
|
scanSummary.path("min_create_date").asText(),
|
||||||
@@ -76,6 +90,24 @@ public final class HistoricalQueueLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void validatePassableCells(List<HistoricalMapCell> cells) {
|
||||||
|
Set<String> siteIds = new LinkedHashSet<String>();
|
||||||
|
Set<String> coordinates = new LinkedHashSet<String>();
|
||||||
|
for (HistoricalMapCell cell : cells) {
|
||||||
|
if (cell.getValue() != 1 && cell.getValue() != 2) continue;
|
||||||
|
if (cell.getSiteId().trim().isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("passable full map site id must not be blank");
|
||||||
|
}
|
||||||
|
if (!siteIds.add(cell.getSiteId())) {
|
||||||
|
throw new IllegalArgumentException("duplicate passable full map site " + cell.getSiteId());
|
||||||
|
}
|
||||||
|
String coordinate = cell.getX() + "," + cell.getY() + "," + cell.getZ();
|
||||||
|
if (!coordinates.add(coordinate)) {
|
||||||
|
throw new IllegalArgumentException("duplicate passable full map coordinate " + coordinate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public HistoricalQueueDataset load(Path basePath) {
|
public HistoricalQueueDataset load(Path basePath) {
|
||||||
if (basePath == null || basePath.getParent() == null || basePath.getParent().getParent() == null) {
|
if (basePath == null || basePath.getParent() == null || basePath.getParent().getParent() == null) {
|
||||||
throw new IllegalArgumentException("invalid history snapshot path");
|
throw new IllegalArgumentException("invalid history snapshot path");
|
||||||
|
|||||||
@@ -13,6 +13,19 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
class HistoricalQueueLoaderTest {
|
class HistoricalQueueLoaderTest {
|
||||||
|
@Test
|
||||||
|
void loadsAndVerifiesTheIndependentCompleteGridSnapshot() {
|
||||||
|
HistoricalQueueDataset data = new HistoricalQueueLoader().load(
|
||||||
|
getClass().getClassLoader(), "shadow/history");
|
||||||
|
|
||||||
|
assertEquals(2552, data.getFullMapRows());
|
||||||
|
assertEquals(2552, data.getFullMapCells().size());
|
||||||
|
assertEquals(1175, data.getFullMapCells().stream()
|
||||||
|
.filter(cell -> cell.getValue() == 1 || cell.getValue() == 2)
|
||||||
|
.count());
|
||||||
|
assertEquals(64, data.getFullMapSha256().length());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void loadsVersionedDatabaseSnapshotAndPreservesOriginalIds() {
|
void loadsVersionedDatabaseSnapshotAndPreservesOriginalIds() {
|
||||||
HistoricalQueueDataset data = new HistoricalQueueLoader().load(
|
HistoricalQueueDataset data = new HistoricalQueueLoader().load(
|
||||||
|
|||||||
25523
javaTest/src/test/resources/shadow/history/full-map-grid.json
Normal file
25523
javaTest/src/test/resources/shadow/history/full-map-grid.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,10 +5,12 @@
|
|||||||
"totalRows": 17136,
|
"totalRows": 17136,
|
||||||
"sampleRows": 240,
|
"sampleRows": 240,
|
||||||
"mapRows": 1129,
|
"mapRows": 1129,
|
||||||
|
"fullMapRows": 2552,
|
||||||
"queryId": "wcs-real-queue-history-replay-v1",
|
"queryId": "wcs-real-queue-history-replay-v1",
|
||||||
"sha256": {
|
"sha256": {
|
||||||
"queue-history-200.json": "8f06d18354c8c199906e75d4243f6d993853d48d1d956fafee36e9f828ab5a94",
|
"queue-history-200.json": "8f06d18354c8c199906e75d4243f6d993853d48d1d956fafee36e9f828ab5a94",
|
||||||
"map-sites.json": "8a16f0c797f6f5e952cd07ce5a50af3a5069c6c102604c20a4e816d2aa88d08d",
|
"map-sites.json": "8a16f0c797f6f5e952cd07ce5a50af3a5069c6c102604c20a4e816d2aa88d08d",
|
||||||
"full-scan-summary.json": "9186836b0c162ea302085fab6ccaf87ffa1733a869f42d2b8bf489a910e36d63"
|
"full-scan-summary.json": "9186836b0c162ea302085fab6ccaf87ffa1733a869f42d2b8bf489a910e36d63",
|
||||||
|
"full-map-grid.json": "f99ce691fa1935fa2aaf4db595143f7757e9baf7b4852f2bace24248c70da7f5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user