Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FineAndDandy committed Nov 16, 2024
1 parent 79a23d8 commit 05f7588
Showing 1 changed file with 147 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,12 +606,6 @@ public void getNonEventFields_param_test() throws TableNotFoundException {
verifyAll();
}

@Test
public void getNonEventFields_key_test() throws TableNotFoundException {
// TODO
assertTrue(false);
}

// this test will fail until AllFieldMetadataHelper.getIndexOnlyFields() properly closes its scanner
@Test
public void getIndexOnlyFields_param_test() throws TableNotFoundException {
Expand Down Expand Up @@ -1085,6 +1079,86 @@ public void expect() throws TableNotFoundException {
return results.toArray(new MethodParamsAndExpectations[0]);
}

private MethodParamsAndExpectations[] getAuthMetadataTableNameVariations(Args[] args, boolean argsInKey, boolean exactMatch, Expectation alwaysExpect) {
if (args == null) {
args = new Args[] {new Args(new Object[] {})};
}
List<MethodParamsAndExpectations> results = new ArrayList<>();

boolean first = true;

MethodParamsAndExpectations base = null;
MethodParamsAndExpectations altAuths = null;
MethodParamsAndExpectations altTable = null;
MethodParamsAndExpectations altTableAndAuths = null;

for (Args a : args) {
if (first || argsInKey) {
base = new MethodParamsAndExpectations(metadataHelper, a.args) {
public void expect() throws Exception {
Scanner s = createMock(Scanner.class);
List<Map.Entry<Key,Value>> entries = new ArrayList<>();
expectScanner("table", s, entries);

if (alwaysExpect != null) {
alwaysExpect.expect();
}
}
};

altAuths = new MethodParamsAndExpectations(alternateAuthsHelper, a.args) {
public void expect() throws Exception {
Scanner s = createMock(Scanner.class);
List<Map.Entry<Key,Value>> entries = new ArrayList<>();
expectScanner("table", s, entries);

if (alwaysExpect != null) {
alwaysExpect.expect();
}
}
};

altTable = new MethodParamsAndExpectations(alternateTableMetadataHelper, a.args) {
public void expect() throws Exception {
Scanner s = createMock(Scanner.class);
List<Map.Entry<Key,Value>> entries = new ArrayList<>();
expectScanner("table2", s, entries);

if (alwaysExpect != null) {
alwaysExpect.expect();
}
}
};

altTableAndAuths = new MethodParamsAndExpectations(alternateHelper, a.args) {
public void expect() throws Exception {
Scanner s = createMock(Scanner.class);
List<Map.Entry<Key,Value>> entries = new ArrayList<>();
expectScanner("table2", s, entries);

if (alwaysExpect != null) {
alwaysExpect.expect();
}
}
};

results.add(base);
results.add(altTable);
results.add(altAuths);
results.add(altTableAndAuths);

first = false;
}

results.add(new MethodParamsAndExpectations(metadataHelper, a.args, base, exactMatch, alwaysExpect));
results.add(new MethodParamsAndExpectations(alternateTableMetadataHelper, a.args, altTable, exactMatch, alwaysExpect));
results.add(new MethodParamsAndExpectations(alternateAuthsHelper, a.args, altAuths, exactMatch, alwaysExpect));
results.add(new MethodParamsAndExpectations(alternateHelper, a.args, altTableAndAuths, exactMatch, alwaysExpect));
}

return results.toArray(new MethodParamsAndExpectations[0]);
}

private MethodParamsAndExpectations getWithExpectation(MetadataHelper helper, Object[] args, MethodParamsAndExpectations cachedObject, boolean exactMatch,
Expectation expectation) {
return new MethodParamsAndExpectations(helper, args, cachedObject, exactMatch) {
Expand Down Expand Up @@ -1144,9 +1218,35 @@ private MethodParamsAndExpectations[] getNonEventFieldExpectations(Args[] args)
return results.toArray(new MethodParamsAndExpectations[0]);
}

// test all methods against all objects
private MethodParamsAndExpectations[] getScansPerCall(Args[] args, int scansPerTable) {
List<MethodParamsAndExpectations> results = new ArrayList<>();

for (int i = 0; i < args.length; i++) {
MethodParamsAndExpectations base = getWithExpectation(metadataHelper, args[i].args, null, false, new ScannerExpectation("table", scansPerTable));
MethodParamsAndExpectations baseAltTable = getWithExpectation(alternateTableMetadataHelper, args[i].args, null, false,
new ScannerExpectation("table2", scansPerTable));
MethodParamsAndExpectations baseAltAuths = getWithExpectation(alternateAuthsHelper, args[i].args, null, false, new ScannerExpectation("table", scansPerTable));
MethodParamsAndExpectations baseAlt = getWithExpectation(alternateHelper, args[i].args, null, false, new ScannerExpectation("table2", scansPerTable));

// no cache hits across any variation here
results.add(base);
results.add(baseAltTable);
results.add(baseAltAuths);
results.add(baseAlt);

// no caching is happening so should be exactly the same for any follow up calls
results.add(getWithExpectation(metadataHelper, args[i].args, base, false, new ScannerExpectation("table", scansPerTable)));
results.add(getWithExpectation(alternateTableMetadataHelper, args[i].args, baseAltTable, false, new ScannerExpectation("table2", scansPerTable)));
results.add(getWithExpectation(alternateAuthsHelper, args[i].args, baseAltAuths, false, new ScannerExpectation("table", scansPerTable)));
results.add(getWithExpectation(alternateHelper, args[i].args, baseAlt, false, new ScannerExpectation("table2", scansPerTable)));
}

return results.toArray(new MethodParamsAndExpectations[0]);
}

// test all public, non-static caching methods for consistency
@Test
public void allTest() throws Exception {
public void cachingConsistencyTest() throws Exception {
// @formatter:off
Map<String,MethodParamsAndExpectations[]> methodToParams = new HashMap<>();
methodToParams.put("1.getQueryModelNames", getExpectedQueryModelNames());
Expand All @@ -1163,21 +1263,27 @@ public void allTest() throws Exception {
s.addScanIterator(anyObject());
s.addScanIterator(anyObject());
}));
methodToParams.put("1.getIndexOnlyFields", getAuthMetadataTableNameVariations(new Args[] {new Args(new Object[] {null}),
new Args(new Object[] {Collections.emptySet()}), new Args(new Object[] {Collections.singleton("filter")})}, false, false));
methodToParams.put("1.getTermFrequencyFields", getAuthMetadataTableNameVariations(new Args[] {new Args(new Object[] {null})}, true));
methodToParams.put("1.getAllFields", getAuthMetadataTableNameVariations(new Args[] {new Args(new Object[] {null}),
new Args(new Object[] {Collections.emptySet()}), new Args(new Object[] {Collections.singleton("filter")})}, false, false));
methodToParams.put("1.getIndexOnlyFields", getAuthMetadataTableNameVariations(new Args[] {
new Args(new Object[] {null}),
new Args(new Object[] {Collections.emptySet()}),
new Args(new Object[] {Collections.singleton("filter")})}, false, false));
methodToParams.put("1.getTermFrequencyFields", getAuthMetadataTableNameVariations(
new Args[] {new Args(new Object[] {null})}, true));
methodToParams.put("1.getAllFields", getAuthMetadataTableNameVariations(new Args[] {
new Args(new Object[] {null}),
new Args(new Object[] {Collections.emptySet()}),
new Args(new Object[] {Collections.singleton("filter")})}, false, false));
methodToParams.put("1.getNonEventFields", getNonEventFieldExpectations(new Args[] {new Args(new Object[] {null}),
new Args(new Object[] {Collections.emptySet()}), new Args(new Object[] {Collections.singleton("filter")})}));
methodToParams.put("2.isReverseIndexed",
getAuthMetadataTableNameVariations(new Args[] {new Args(new Object[] {"f1", Collections.emptySet()}),
new Args(new Object[] {"f1", Collections.singleton("filter")}), new Args(new Object[] {"f2", Collections.singleton("filter")})},
true, false));
methodToParams.put("2.isIndexed",
getAuthMetadataTableNameVariations(new Args[] {new Args(new Object[] {"f1", Collections.emptySet()}),
new Args(new Object[] {"f1", Collections.singleton("filter")}), new Args(new Object[] {"f2", Collections.singleton("filter")})},
true, false));
new Args(new Object[] {Collections.emptySet()}),
new Args(new Object[] {Collections.singleton("filter")})}));
methodToParams.put("2.isReverseIndexed", getAuthMetadataTableNameVariations(new Args[] {
new Args(new Object[] {"f1", Collections.emptySet()}),
new Args(new Object[] {"f1", Collections.singleton("filter")}),
new Args(new Object[] {"f2", Collections.singleton("filter")})}, true, false));
methodToParams.put("2.isIndexed", getAuthMetadataTableNameVariations(new Args[] {
new Args(new Object[] {"f1", Collections.emptySet()}),
new Args(new Object[] {"f1", Collections.singleton("filter")}),
new Args(new Object[] {"f2", Collections.singleton("filter")})}, true, false));
methodToParams.put("2.isTokenized", getAuthMetadataTableNameVariations(new Args[] {
new Args(new Object[] {"f1", Collections.emptySet()}),
new Args(new Object[] {"f1", Collections.singleton("filter")}),
Expand Down Expand Up @@ -1257,6 +1363,10 @@ public void allTest() throws Exception {
new Args(new Object[] {Collections.emptySet()}),
new Args(new Object[] {Collections.singleton("filter")})}, false, false));
methodToParams.put("0.loadIndexOnlyFields", getNoArgAuthMetadataTableNameVariations(null));
// TODO special cases
methodToParams.put("2.getQueryModel", new MethodParamsAndExpectations[] {});
methodToParams.put("3.getQueryModel", new MethodParamsAndExpectations[] {});
methodToParams.put("4.getQueryModel", new MethodParamsAndExpectations[] {});

// uncached methods that can safely be skipped
methodToParams.put("0.toString", new MethodParamsAndExpectations[] {});
Expand All @@ -1280,14 +1390,20 @@ public void allTest() throws Exception {
methodToParams.put("0.getMetadataTableName", new MethodParamsAndExpectations[] {});
methodToParams.put("0.getTypeCacheSize", new MethodParamsAndExpectations[] {});
methodToParams.put("1.setTypeCacheSize", new MethodParamsAndExpectations[] {});

// not currently cached but should probably cover with tests
methodToParams.put("0.getTypeMetadataMap", new MethodParamsAndExpectations[] {});
methodToParams.put("2.getQueryModel", new MethodParamsAndExpectations[] {});
methodToParams.put("3.getQueryModel", new MethodParamsAndExpectations[] {});
methodToParams.put("4.getQueryModel", new MethodParamsAndExpectations[] {});
methodToParams.put("0.getTypeCacheExpirationInMinutes", new MethodParamsAndExpectations[] {});
methodToParams.put("1.setTypeCacheExpirationInMinutes", new MethodParamsAndExpectations[] {});

// not currently cached, verify scanners so if caching is added things will fail
methodToParams.put("0.getTypeMetadataMap", getScansPerCall(new Args[] {
new Args(new Object[] {})}, 2));
methodToParams.put("0.loadTermFrequencyFields", getScansPerCall(new Args[] {
new Args(new Object[] {})}, 1));
methodToParams.put("0.loadAllFields", getScansPerCall(new Args[] {
new Args(new Object[] {})}, 1));
// TODO from here down for scan verification
methodToParams.put("3.getCardinalityForField", new MethodParamsAndExpectations[] {});
methodToParams.put("4.getCardinalityForField", new MethodParamsAndExpectations[] {});
methodToParams.put("2.getCountsByFieldInDay", new MethodParamsAndExpectations[] {});
methodToParams.put("1.getCountsByFieldInDayWithTypes", new MethodParamsAndExpectations[] {});
methodToParams.put("2.getCountsByFieldInDayWithTypes", new MethodParamsAndExpectations[] {});
methodToParams.put("3.getCountsByFieldInDayWithTypes", new MethodParamsAndExpectations[] {});
Expand All @@ -1299,11 +1415,6 @@ public void allTest() throws Exception {
methodToParams.put("4.getEarliestOccurrenceOfFieldWithType", new MethodParamsAndExpectations[] {});
methodToParams.put("3.getFieldIndexHoles", new MethodParamsAndExpectations[] {});
methodToParams.put("3.getReversedFieldIndexHoles", new MethodParamsAndExpectations[] {});
methodToParams.put("0.loadAllFields", new MethodParamsAndExpectations[] {});
methodToParams.put("0.loadTermFrequencyFields", new MethodParamsAndExpectations[] {});
// TBD
methodToParams.put("2.getCountsByFieldInDay", new MethodParamsAndExpectations[] {});

// @formatter:on

// test that all methods are tested
Expand All @@ -1319,9 +1430,9 @@ public void allTest() throws Exception {

// TODO delete this after all methods are added
// isolate a single test
// if (!method.getName().equals("getFieldsForDatatype")) {
// continue;
// }
if (!method.getName().equals("loadAllFields")) {
continue;
}

String lookupName = method.getParameterCount() + "." + method.getName();

Expand Down

0 comments on commit 05f7588

Please sign in to comment.