Skip to content

Commit 50c7401

Browse files
committed
Close all closable objects in GatewayTest
1 parent eba7df3 commit 50c7401

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/com/microsoft/azure/documentdb/test/GatewayTests.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void cleanUpGeneratedDatabases() throws DocumentClientException {
131131
new SqlParameterCollection(new SqlParameter("@id", id))),
132132
null).getQueryIterable().iterator().next();
133133
if (database != null) {
134-
client.deleteDatabase(database.getSelfLink(), null);
134+
client.deleteDatabase(database.getSelfLink(), null).close();;
135135
}
136136
}
137137
}
@@ -332,11 +332,11 @@ public void testDatabaseCrud() throws DocumentClientException {
332332
Database oneDbFromRead = client.readDatabase(replacedDb.getSelfLink(), null).getResource();
333333
Assert.assertEquals(replacedDb.getId(), oneDbFromRead.getId());
334334
// Delete database.
335-
client.deleteDatabase(replacedDb.getSelfLink(), null);
335+
client.deleteDatabase(replacedDb.getSelfLink(), null).close();
336336

337337
// Read database after deletion.
338338
try {
339-
client.readDatabase(createdDb.getSelfLink(), null);
339+
client.readDatabase(createdDb.getSelfLink(), null).close();
340340
Assert.fail("Exception didn't happen.");
341341
} catch (DocumentClientException e) {
342342
Assert.assertEquals(404, e.getStatusCode());
@@ -372,11 +372,11 @@ public void testCollectionCrud() throws DocumentClientException {
372372
null).getQueryIterable().toList();
373373
Assert.assertTrue(collections.size() > 0);
374374
// Delete collection.
375-
client.deleteCollection(createdCollection.getSelfLink(), null);
375+
client.deleteCollection(createdCollection.getSelfLink(), null).close();
376376
// Read collection after deletion.
377377

378378
try {
379-
client.readCollection(createdCollection.getSelfLink(), null);
379+
client.readCollection(createdCollection.getSelfLink(), null).close();
380380
Assert.fail("Exception didn't happen.");
381381
} catch (DocumentClientException e) {
382382
Assert.assertEquals(404, e.getStatusCode());
@@ -397,7 +397,7 @@ public void testQueryIterableCrud() throws DocumentClientException {
397397
// Create 10 documents.
398398
for (int i = 0; i < numOfDocuments; ++i) {
399399
Document documentDefinition = new Document("{ 'name': 'For paging test' }");
400-
client.createDocument(this.collectionForTest.getSelfLink(), documentDefinition, null, false);
400+
client.createDocument(this.collectionForTest.getSelfLink(), documentDefinition, null, false).close();
401401
}
402402

403403
int numOfDocumentsPerPage = numOfDocuments / 5;
@@ -471,7 +471,7 @@ public void testCollectionIndexingPolicy() throws DocumentClientException {
471471
" 'indexingMode': 'Lazy'" +
472472
" }" +
473473
"}");
474-
client.deleteCollection(this.collectionForTest.getSelfLink(), null);
474+
client.deleteCollection(this.collectionForTest.getSelfLink(), null).close();
475475
DocumentCollection lazyCollection = client.createCollection(this.databaseForTest.getSelfLink(),
476476
lazyCollectionDefinition,
477477
null).getResource();
@@ -485,7 +485,7 @@ public void testCollectionIndexingPolicy() throws DocumentClientException {
485485
" 'indexingMode': 'Consistent'" +
486486
" }" +
487487
"}");
488-
client.deleteCollection(lazyCollection.getSelfLink(), null);
488+
client.deleteCollection(lazyCollection.getSelfLink(), null).close();
489489
DocumentCollection consistentCollection = client.createCollection(this.databaseForTest.getSelfLink(),
490490
consistentCollectionDefinition,
491491
null).getResource();
@@ -509,7 +509,7 @@ public void testCollectionIndexingPolicy() throws DocumentClientException {
509509
" ]" +
510510
" }" +
511511
"}");
512-
client.deleteCollection(consistentCollection.getSelfLink(), null);
512+
client.deleteCollection(consistentCollection.getSelfLink(), null).close();
513513
DocumentCollection collectionWithSecondaryIndex = client.createCollection(this.databaseForTest.getSelfLink(),
514514
collectionDefinition,
515515
null).getResource();
@@ -592,11 +592,11 @@ public void testDocumentCrud() throws DocumentClientException {
592592
Assert.assertEquals(rr.getStatusCode(), HttpStatus.SC_NOT_MODIFIED);
593593

594594
// delete document
595-
client.deleteDocument(replacedDocument.getSelfLink(), null);
595+
client.deleteDocument(replacedDocument.getSelfLink(), null).close();
596596

597597
// read documents after deletion
598598
try {
599-
client.readDocument(replacedDocument.getSelfLink(), null);
599+
client.readDocument(replacedDocument.getSelfLink(), null).close();
600600
Assert.fail("Exception didn't happen.");
601601
} catch (DocumentClientException e) {
602602
Assert.assertEquals(404, e.getStatusCode());
@@ -738,7 +738,7 @@ public int read() throws IOException {
738738
// Create attachment with invalid content type.
739739
ReadableStream mediaStream = new ReadableStream("stream content.");
740740
try {
741-
client.createAttachment(document.getSelfLink(), mediaStream, invalidMediaOptions);
741+
client.createAttachment(document.getSelfLink(), mediaStream, invalidMediaOptions).close();
742742
Assert.assertTrue(false); // This line shouldn't execute.
743743
} catch (DocumentClientException e) {
744744
Assert.assertEquals(400, e.getStatusCode());
@@ -755,7 +755,7 @@ public int read() throws IOException {
755755
mediaStream = new ReadableStream("stream content");
756756
// Create colliding attachment.
757757
try {
758-
client.createAttachment(document.getSelfLink(), mediaStream, validMediaOptions);
758+
client.createAttachment(document.getSelfLink(), mediaStream, validMediaOptions).close();
759759
Assert.fail("Exception didn't happen.");
760760
} catch (DocumentClientException e) {
761761
Assert.assertEquals(409, e.getStatusCode());
@@ -786,7 +786,7 @@ public int read() throws IOException {
786786
attachment.set("Author", "new author");
787787

788788
// Replace the attachment.
789-
client.replaceAttachment(attachment, null);
789+
client.replaceAttachment(attachment, null).close();
790790
Assert.assertEquals("Book", attachment.getString("MediaType"));
791791
Assert.assertEquals("new author", attachment.getString("Author"));
792792
// Read attachment media.
@@ -829,7 +829,7 @@ public int read() throws IOException {
829829
Assert.assertEquals(validAttachment.getMediaLink(), attachment.getMediaLink());
830830
Assert.assertEquals(validAttachment.getContentType(), attachment.getContentType());
831831
// Deleting attachment.
832-
client.deleteAttachment(attachment.getSelfLink(), null);
832+
client.deleteAttachment(attachment.getSelfLink(), null).close();
833833
// read attachments after deletion
834834
attachments = client.readAttachments(document.getSelfLink(), null).getQueryIterable().toList();
835835
Assert.assertEquals(0, attachments.size());
@@ -861,7 +861,7 @@ public void testTriggerCrud() throws DocumentClientException {
861861

862862
Document document = new Document();
863863
document.setId("noname");
864-
client.createDocument(this.collectionForTest.getSelfLink(), document, options, false);
864+
client.createDocument(this.collectionForTest.getSelfLink(), document, options, false).close();
865865

866866
// replace...
867867
String id = GatewayTests.getUID();
@@ -892,7 +892,7 @@ public void testTriggerCrud() throws DocumentClientException {
892892
Assert.fail("Query fail to find trigger");
893893
}
894894

895-
client.deleteTrigger(newTrigger.getSelfLink(), null);
895+
client.deleteTrigger(newTrigger.getSelfLink(), null).close();
896896
}
897897

898898
@Test
@@ -942,7 +942,7 @@ public void testStoredProcedureCrud() throws DocumentClientException {
942942
Assert.fail("Query fail to find StoredProcedure");
943943
}
944944

945-
client.deleteStoredProcedure(newStoredProcedure.getSelfLink(), null);
945+
client.deleteStoredProcedure(newStoredProcedure.getSelfLink(), null).close();
946946
}
947947

948948
@Test
@@ -1088,7 +1088,7 @@ public void testUserDefinedFunctionCrud() throws DocumentClientException {
10881088
Assert.fail("Query fail to find UserDefinedFunction");
10891089
}
10901090
}
1091-
client.deleteUserDefinedFunction(newUdf.getSelfLink(), null);
1091+
client.deleteUserDefinedFunction(newUdf.getSelfLink(), null).close();
10921092
}
10931093

10941094
@Test
@@ -1126,10 +1126,10 @@ public void testUserCrud() throws DocumentClientException {
11261126
user = client.readUser(replacedUser.getSelfLink(), null).getResource();
11271127
Assert.assertEquals(replacedUser.getId(), user.getId());
11281128
// Delete user.
1129-
client.deleteUser(user.getSelfLink(), null);
1129+
client.deleteUser(user.getSelfLink(), null).close();
11301130
// Read user after deletion.
11311131
try {
1132-
client.readUser(user.getSelfLink(), null);
1132+
client.readUser(user.getSelfLink(), null).close();
11331133
Assert.fail("Exception didn't happen.");
11341134
} catch (DocumentClientException e) {
11351135
Assert.assertEquals(404, e.getStatusCode());
@@ -1183,10 +1183,10 @@ public void testPermissionCrud() throws DocumentClientException {
11831183
permission = client.readPermission(replacedPermission.getSelfLink(), null).getResource();
11841184
Assert.assertEquals(replacedPermission.getId(), permission.getId());
11851185
// Delete permission.
1186-
client.deletePermission(replacedPermission.getSelfLink(), null);
1186+
client.deletePermission(replacedPermission.getSelfLink(), null).close();
11871187
// Read permission after deletion.
11881188
try {
1189-
client.readPermission(permission.getSelfLink(), null);
1189+
client.readPermission(permission.getSelfLink(), null).close();
11901190
Assert.fail("Exception didn't happen.");
11911191
} catch (DocumentClientException e) {
11921192
Assert.assertEquals(404, e.getStatusCode());
@@ -1297,7 +1297,7 @@ public void testAuthorization() throws DocumentClientException {
12971297
clientForCollection1.readCollection(collectionForTest.getSelfLink(), null).getResource();
12981298
// 2. Failure-- Use Col1 Permission to delete
12991299
try {
1300-
clientForCollection1.deleteCollection(obtainedCollection1.getSelfLink(), null);
1300+
clientForCollection1.deleteCollection(obtainedCollection1.getSelfLink(), null).close();
13011301
Assert.fail("Exception didn't happen.");
13021302
} catch (DocumentClientException e) {
13031303
Assert.assertEquals(403, e.getStatusCode());

0 commit comments

Comments
 (0)