Skip to content

Commit

Permalink
Clean up linting file, Junit test and builder refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-zhu committed Jul 12, 2019
1 parent fae3cad commit b64963e
Show file tree
Hide file tree
Showing 164 changed files with 1,717 additions and 3,810 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@
import com.azure.core.test.TestMode;
import com.azure.core.util.configuration.ConfigurationManager;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.file.models.FileProperty;
import com.azure.storage.file.models.FileRef;
import java.time.Duration;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -169,24 +174,51 @@ public void listFilesAndDirectoriesFromDirClient() {
StepVerifier.create(client.create())
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
LinkedList<FileRef> fileRefs = new LinkedList<>();
List<FileRef> fileRefs = new ArrayList<>();
int repeatTimes = 3;
// generate some subdirectories
String fileNameSameLayer = testResourceNamer.randomName("sameLayer", 16);
String fileNameNextLayer = testResourceNamer.randomName("nextLayer", 16);

for (int i = 0; i < repeatTimes; i++) {
String directoryName = dirName + i;
StepVerifier.create(client.createSubDirectory(directoryName))
DirectoryAsyncClient subDirectoryClient = client.getSubDirectoryClient(directoryName);
StepVerifier.create(subDirectoryClient.create())
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
fileRefs.add(new FileRef(directoryName, true, null));

fileNameSameLayer = fileNameSameLayer + i;
fileNameNextLayer = fileNameNextLayer + i;

StepVerifier.create(client.createFile(fileNameSameLayer, 1024))
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
fileRefs.add(new FileRef(fileNameSameLayer, false, new FileProperty().contentLength(1024)));
StepVerifier.create(subDirectoryClient.createFile(fileNameNextLayer, 1024))
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();

}

StepVerifier.create(client.listFilesAndDirectories(dirName, null))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.pop(), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.pop(), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.pop(), fileRef))
Collections.sort(fileRefs, new LexicographicComparator());
StepVerifier.create(client.listFilesAndDirectories(null, null))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(0), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(1), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(2), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(3), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(4), fileRef))
.assertNext(fileRef -> FileTestHelpers.assertFileRefsAreEqual(fileRefs.get(5), fileRef))
.verifyComplete();
}

class LexicographicComparator implements Comparator<FileRef> {
@Override
public int compare(FileRef a, FileRef b) {
return a.name().compareToIgnoreCase(b.name());
}
}

@Override
public void getHandlesFromDirClient() {
// TODO: Need to open channel and create handlers first.
Expand All @@ -200,14 +232,24 @@ public void getHandlesFromDirClient() {

@Override
public void forceCloseHandlesFromDirClient() {
StepVerifier.create(client.create())
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
client.getHandles(null, true).doOnEach(
handleItem -> {
client.forceCloseHandles(handleItem.get().handleId(), true).doOnEach(
numOfClosedHandles -> Assert.assertTrue(numOfClosedHandles.get() > 0)
);
// StepVerifier.create(client.create())
// .assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
// .verifyComplete();
// StepVerifier.create(client.getHandles(null, true))
// .assertNext(handleItem -> {
// StepVerifier.create(client.forceCloseHandles(handleItem.handleId(), true))
// .assertNext(numOfClosedHandles -> Assert.assertTrue(numOfClosedHandles.longValue() > 0))
// .verifyComplete();
// })
// .verifyComplete();
client.create().block();
CountDownLatch latch = new CountDownLatch(1);
client.getHandles(null, true).subscribe(
response -> {
StepVerifier.create(client.forceCloseHandles(response.handleId(), true))
.assertNext(forceCloseHandles -> Assert.assertTrue(forceCloseHandles > 0))
.verifyComplete();
latch.countDown();
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.azure.core.http.policy.HttpLogDetailLevel;
import com.azure.core.implementation.http.UrlBuilder;
import com.azure.core.test.TestMode;
import com.azure.core.test.utils.TestResourceNamer;
import com.azure.core.util.configuration.ConfigurationManager;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.file.models.FileRef;
Expand All @@ -18,6 +17,7 @@
import org.junit.BeforeClass;

import static com.azure.storage.file.FileTestHelpers.setupClient;
import static org.junit.Assert.assertTrue;

public class DirectoryClientTests extends DirectoryClientTestBase {
private final ClientLogger directoryLogger = new ClientLogger(DirectoryClientTests.class);
Expand Down Expand Up @@ -152,20 +152,29 @@ public void setMetadataInvalidKeyFromDirClient() {
public void listFilesAndDirectoriesFromDirClient() {
FileTestHelpers.assertResponseStatusCode(directoryClient.create(), 201);
int repeatTimes = 3;
String fileNameSameLayer = testResourceNamer.randomName("sameLayer", 16);
String fileNameNextLayer = testResourceNamer.randomName("nextLayer", 16);
for (int i = 0; i < repeatTimes; i++) {
DirectoryClient subDirClient = directoryClient.getSubDirectoryClient(dirName + i);
FileTestHelpers.assertResponseStatusCode(subDirClient.create(), 201);
String fileName = testResourceNamer.randomName("file", 16);
FileTestHelpers.assertResponseStatusCode(subDirClient.createFile(fileName, 1024), 201);
fileNameSameLayer = fileNameSameLayer + i;
fileNameNextLayer = fileNameNextLayer + i;
FileTestHelpers.assertResponseStatusCode(directoryClient.createFile(fileNameSameLayer, 1024), 201);
FileTestHelpers.assertResponseStatusCode(subDirClient.createFile(fileNameNextLayer, 1024), 201);
}
Iterable<FileRef> fileRefs = directoryClient.listFilesAndDirectories(dirName, null);

Iterable<FileRef> fileRefs = directoryClient.listFilesAndDirectories();

int count = 0;
Iterator<FileRef> it = fileRefs.iterator();
while (it.hasNext()) {
count++;
Assert.assertNotNull(it.next());
FileRef ref = it.next();
Assert.assertNotNull(ref);
if (!ref.isDirectory()) {
assertTrue("It is supposed to list the files in same layer.", ref.name().contains("samelayer"));
}
}
System.out.println(count);
Assert.assertEquals(repeatTimes * 2, count);
}

Expand All @@ -182,7 +191,7 @@ public void forceCloseHandlesFromDirClient() {
directoryClient.getHandles(null, true).forEach(
handleItem -> {
directoryClient.forceCloseHandles(handleItem.handleId(), true).forEach(
numberOfClosedHandles -> Assert.assertTrue(numberOfClosedHandles > 0)
numberOfClosedHandles -> assertTrue(numberOfClosedHandles > 0)
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,20 @@ public static void tearDown() {

@Override
public void createFromFileClient() {
StepVerifier.create(fileAsyncClient.create(1024, null, null))
StepVerifier.create(fileAsyncClient.create(1024))
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
StepVerifier.create(fileAsyncClient.getProperties())
.assertNext(filePropertiesResponse -> Assert.assertTrue(filePropertiesResponse.value().contentLength() == 1024));
}

@Override
public void createExcessMaxSizeFromFileClient() {
StepVerifier.create(fileAsyncClient.create(1024 * 1024 * 1024 * 1024, null, null))
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 201))
.verifyComplete();
StepVerifier.create(fileAsyncClient.getProperties())
.assertNext(filePropertiesResponse -> Assert.assertTrue(filePropertiesResponse.value().contentLength() == 0));
}

@Override
Expand Down Expand Up @@ -137,8 +141,10 @@ public void uploadToStorageAndDownloadToFile() throws Exception {

@Override
public void deleteFromFileClient() {
fileAsyncClient.create(1024, null, null).subscribe();
fileAsyncClient.delete().subscribe();
fileAsyncClient.create(1024, null, null).block();
StepVerifier.create(fileAsyncClient.delete())
.assertNext(response -> FileTestHelpers.assertResponseStatusCode(response, 202))
.verifyComplete();
}

@Override
Expand Down Expand Up @@ -197,7 +203,7 @@ public void forceCloseHandlesFromFileClient() {
//TODO: need to create a handle first
fileAsyncClient.create(1024).block();
CountDownLatch latch = new CountDownLatch(1);
fileAsyncClient.listHandles().subscribe(
fileAsyncClient.listHandles(10).subscribe(
response -> {
StepVerifier.create(fileAsyncClient.forceCloseHandles(response.handleId()))
.assertNext(forceCloseHandles -> Assert.assertTrue(forceCloseHandles > 0))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void abortCopy() {
public void downloadWithProperties() {
fileClient.create(1024, null, null);
FileRange range = new FileRange(0, 1024);
FileTestHelpers.assertResponseStatusCode(fileClient.downloadWithProperties(range, null), 206);
FileTestHelpers.assertResponseListStatusCode(fileClient.downloadWithProperties(range, null), Arrays.asList(200, 206));
}

@Override
Expand All @@ -135,7 +135,7 @@ public void uploadToStorageAndDownloadToFile() throws Exception {
@Override
public void deleteFromFileClient() {
fileClient.create(1024, null, null);
fileClient.delete();
FileTestHelpers.assertResponseStatusCode(fileClient.delete(), 202);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;

public abstract class FileClientTestBase extends TestBase {
Expand All @@ -20,6 +21,9 @@ public abstract class FileClientTestBase extends TestBase {
@Rule
public TestName testName = new TestName();

@Rule
public ExpectedException thrown = ExpectedException.none();

/**
* Gets the name of the current test being run.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.azure.core.http.rest.Response;
import com.azure.core.util.logging.ClientLogger;
import com.azure.storage.file.models.AccessPolicy;
import com.azure.storage.file.models.DirectoryProperties;
import com.azure.storage.file.models.ShareProperties;
import com.azure.storage.file.models.ShareSnapshotInfo;
import com.azure.storage.file.models.ShareStatistics;
Expand Down Expand Up @@ -70,8 +71,9 @@ public void afterTest() {
public void getRootDirectoryDoesNotCreateADirectory() {
shareClient.create();
DirectoryClient directoryClient = shareClient.getRootDirectoryClient();
Assert.assertEquals(directoryClient.getProperties().statusCode(), 200);
Assert.assertNotNull(directoryClient.getProperties().value().eTag());
Response<DirectoryProperties> response = directoryClient.getProperties();
Assert.assertEquals(response.statusCode(), 200);
Assert.assertNotNull(response.value().eTag());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"networkCallRecords" : [ ],
"variables" : [ "file31195601" ]
"variables" : [ "file43189fe6" ]
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "https://sima.file.core.windows.net/dirsharename/directory23379f?restype=directory",
"Uri" : "https://sima.file.core.windows.net/dirsharename/directory228250?restype=directory",
"Headers" : {
"x-ms-version" : "2018-11-09",
"User-Agent" : "azsdk-java-storage-file/1.0.0-SNAPSHOT 1.8.0_201; Windows 10 10.0"
},
"Response" : {
"x-ms-version" : "2018-11-09",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "\"0x8D7068ADDBDEDB0\"",
"Last-Modified" : "Fri, 12 Jul 2019 05:36:19 GMT",
"ETag" : "\"0x8D706A8842A398B\"",
"Last-Modified" : "Fri, 12 Jul 2019 09:08:33 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "250bf19d-b01a-0014-6d73-380cf6000000",
"x-ms-request-id" : "9e60669a-501a-0051-6e91-38d167000000",
"x-ms-request-server-encrypted" : "true",
"Date" : "Fri, 12 Jul 2019 05:36:18 GMT"
"Date" : "Fri, 12 Jul 2019 09:08:33 GMT"
}
}, {
"Method" : "PUT",
"Uri" : "https://sima.file.core.windows.net/dirsharename/directory23379f?restype=directory&comp=metadata",
"Uri" : "https://sima.file.core.windows.net/dirsharename/directory228250?restype=directory&comp=metadata",
"Headers" : {
"x-ms-version" : "2018-11-09",
"User-Agent" : "azsdk-java-storage-file/1.0.0-SNAPSHOT 1.8.0_201; Windows 10 10.0"
},
"Response" : {
"x-ms-version" : "2018-11-09",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "\"0x8D7068ADDC9AFB0\"",
"Last-Modified" : "Fri, 12 Jul 2019 05:36:19 GMT",
"ETag" : "\"0x8D706A8843F9A3E\"",
"Last-Modified" : "Fri, 12 Jul 2019 09:08:33 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "200",
"x-ms-request-id" : "250bf19f-b01a-0014-6e73-380cf6000000",
"x-ms-request-id" : "9e60669b-501a-0051-6f91-38d167000000",
"x-ms-request-server-encrypted" : "true",
"Date" : "Fri, 12 Jul 2019 05:36:18 GMT"
"Date" : "Fri, 12 Jul 2019 09:08:33 GMT"
}
} ],
"variables" : [ "directory23379f" ]
"variables" : [ "directory228250" ]
}
38 changes: 0 additions & 38 deletions storage/client/file/src/test/resources/session-records/create.json

This file was deleted.

This file was deleted.

Loading

0 comments on commit b64963e

Please sign in to comment.