Skip to content

Commit

Permalink
rm display function
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiangs18 committed Jan 17, 2024
1 parent c2fb5a1 commit 0f7db8e
Showing 1 changed file with 29 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void nullConstructor() throws Exception {
assertThat("incorrect exception message", e.getMessage(), is("db"));
}
}

@Test
public void startUpAndCheckConfigDoc() throws Exception {
final MongoDatabase db = mc.getDatabase("startUpAndCheckConfigDoc");
Expand All @@ -42,30 +42,30 @@ public void startUpAndCheckConfigDoc() throws Exception {
assertThat("Only one config doc", col.countDocuments(), is(1L));
final FindIterable<Document> c = col.find();
final Document d = c.first();

assertThat("correct config key & value", (String)d.get("schema"), is("schema"));
assertThat("not in update", (Boolean)d.get("inupdate"), is(false));
assertThat("schema v1", (Integer)d.get("schemaver"), is(1));

//check startup works with the config object in place
final MongoStorage ms = new MongoStorage(db);
ms.setCustomRole(new CustomRole("foo", "bar"));
assertThat("failed basic storage operation", ms.getCustomRoles(),
is(set(new CustomRole("foo", "bar"))));
}

@Test
public void startUpWith2ConfigDocs() throws Exception {
final MongoDatabase db = mc.getDatabase("startUpWith2ConfigDocs");

final Document m = new Document("schema", "schema")
.append("inupdate", false)
.append("schemaver", 1);

db.getCollection("config").insertMany(Arrays.asList(m,
// need to create a new document to create a new mongo _id
new Document(m)));

final Pattern errorPattern = Pattern.compile(
"Failed to create index: Write failed with error code 11000 and error message " +
"'(exception: )?(.*)E11000 duplicate key error (index|collection): " +
Expand All @@ -79,36 +79,36 @@ public void startUpWith2ConfigDocs() throws Exception {
assertThat("exception did not match: \n" + e.getMessage(), match.matches(), is(true));
}
}

@Test
public void startUpWithBadSchemaVersion() throws Exception {
final MongoDatabase db = mc.getDatabase("startUpWithBadSchemaVersion");

final Document m = new Document("schema", "schema")
.append("inupdate", false)
.append("schemaver", 4);

db.getCollection("config").insertOne(m);

failMongoStart(db, new StorageInitException(
"Incompatible database schema. Server is v1, DB is v4"));
}

@Test
public void startUpWithUpdateInProgress() throws Exception {
final MongoDatabase db = mc.getDatabase("startUpWithUpdateInProgress");

final Document m = new Document("schema", "schema")
.append("inupdate", true)
.append("schemaver", 1);

db.getCollection("config").insertOne(m);

failMongoStart(db, new StorageInitException(
"The database is in the middle of an update from v1 of the " +
"schema. Aborting startup."));
}

private void failMongoStart(final MongoDatabase db, final Exception exp)
throws Exception {
try {
Expand All @@ -118,13 +118,13 @@ private void failMongoStart(final MongoDatabase db, final Exception exp)
TestCommon.assertExceptionCorrect(e, exp);
}
}

/* The following tests ensure that all indexes are created correctly. The collection names
* are tested so that if a new collection is added the test will fail without altering
* are tested so that if a new collection is added the test will fail without altering
* said test, at which time the coder will hopefully read this notice and add index tests
* for the new collection.
*/

@Test
public void checkCollectionNames() throws Exception {
final Set<String> names = new HashSet<>();
Expand All @@ -148,7 +148,7 @@ public void checkCollectionNames() throws Exception {
db.listCollectionNames().forEach((Consumer<String>) names::add);
assertThat("incorrect collection names", names, is(expected));
}

@Test
public void indexesConfig() {
final Set<Document> indexes = new HashSet<>();
Expand Down Expand Up @@ -178,7 +178,7 @@ public void indexesConfigApp() {
.append("name", "_id_")
)));
}

@Test
public void indexesConfigExt() {
final Set<Document> indexes = new HashSet<>();
Expand Down Expand Up @@ -208,7 +208,7 @@ public void indexesConfigProv() {
.append("name", "_id_")
)));
}

@Test
public void indexesCustRoles() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -223,7 +223,7 @@ public void indexesCustRoles() {
.append("name", "_id_")
)));
}

@Test
public void indexesTestCustRoles() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -242,7 +242,7 @@ public void indexesTestCustRoles() {
.append("expireAfterSeconds", 0L)
)));
}

@Test
public void indexesTempData() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -269,7 +269,7 @@ public void indexesTempData() {
.append("name", "id_1")
)));
}

@Test
public void indexesTokens() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -295,7 +295,7 @@ public void indexesTokens() {
.append("name", "id_1")
)));
}

@Test
public void indexesTestTokens() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -321,7 +321,7 @@ public void indexesTestTokens() {
.append("name", "id_1")
)));
}

@Test
public void indexesUsers() {
final Set<Document> indexes = new HashSet<>();
Expand All @@ -338,7 +338,7 @@ public void indexesUsers() {
.append("key", new Document("_id", 1))
.append("name", "_id_"),
new Document("v", indexVer)
.append("unique", true)
.append("unique", true)
.append("key", new Document("idents.id", 1))
.append("name", "idents.id_1")
.append("sparse", true),
Expand All @@ -356,7 +356,7 @@ public void indexesUsers() {
.append("sparse", true)
)));
}

@Test
public void indexesTestUsers() {
final Set<Document> indexes = new HashSet<>();
Expand Down Expand Up @@ -396,21 +396,4 @@ public void updateIndexes(final String name, final Set<Document> indexes) {
indexes.add(index);
}
}

public void display(final Set<Document> indexes) {
for (Document doc: indexes) {
for (String key: doc.keySet()) {
if (key.equals("key")) {
Document dVal = (Document) doc.get(key);
for (String dkey: dVal.keySet()) {
Object dval = dVal.get(dkey);
System.out.println("key: " + dkey + " |" + " value: " + dval + " |" + " type: " + dval.getClass().getName());
}
} else {
Object val = doc.get(key);
System.out.println("key: " + key + " |" + " value: " + val + " |" + " type: " + val.getClass().getName());
}
}
}
}
}

0 comments on commit 0f7db8e

Please sign in to comment.