Skip to content

Commit

Permalink
fix missing latch releases in filesystem plugin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
breautek committed Oct 23, 2024
1 parent 499d6f1 commit 3984592
Showing 1 changed file with 46 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -527,61 +527,63 @@ public void canTruncateFileWithNewContent() throws InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
activityRule.getScenario().onActivity(activity -> {
activity.setOnReadyCallback(() -> {
try {
int port = activity.getFuseContext().getAPIPort();
String secret = activity.getFuseContext().getAPISecret();

int port = activity.getFuseContext().getAPIPort();
String secret = activity.getFuseContext().getAPISecret();

String testFile = "file:///data/data/com.breautek.fuse.filesystem.test/files/truncateTest1";
String testFile = "file:///data/data/com.breautek.fuse.filesystem.test/files/truncateTest1";

byte[] newContent = "new content".getBytes();
byte[] newContent = "new content".getBytes();

FuseTestAPIClient client;
try {
byte[] content = createParamsBuffer(testFile, newContent);
client = new FuseTestAPIClient.Builder()
.setFuseContext(activity.getFuseContext())
.setAPIPort(port)
.setAPISecret(secret)
.setPluginID("FuseFilesystem")
.setType("application/octet-stream")
.setEndpoint("/file/truncate")
.setContent(content)
.build();
} catch (Exception e) {
latch.countDown();
throw new RuntimeException(e);
}
FuseTestAPIClient client;
try {
byte[] content = createParamsBuffer(testFile, newContent);
client = new FuseTestAPIClient.Builder()
.setFuseContext(activity.getFuseContext())
.setAPIPort(port)
.setAPISecret(secret)
.setPluginID("FuseFilesystem")
.setType("application/octet-stream")
.setEndpoint("/file/truncate")
.setContent(content)
.build();
} catch (Exception e) {
throw new RuntimeException(e);
}

FuseTestAPIClient.FuseAPITestResponse response = client.execute();
assertEquals(200, response.getStatus());
FuseTestAPIClient.FuseAPITestResponse response = client.execute();
assertEquals(200, response.getStatus());

File file = new File(Uri.parse(testFile).getPath());
File file = new File(Uri.parse(testFile).getPath());

assertEquals(newContent.length, file.length());
assertEquals(newContent.length, file.length());

String newContentStr = null;
FileReader reader = null;
try {
reader = new FileReader(file);
char[] readerBuffer = new char[newContent.length];
reader.read(readerBuffer);
newContentStr = new String(readerBuffer);
reader.close();
} catch (Exception e) {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
latch.countDown();
throw new RuntimeException(ex);
String newContentStr = null;
FileReader reader = null;
try {
reader = new FileReader(file);
char[] readerBuffer = new char[newContent.length];
reader.read(readerBuffer);
newContentStr = new String(readerBuffer);
reader.close();
} catch (Exception e) {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
throw new RuntimeException(e);
}

assertEquals("new content", newContentStr);
latch.countDown();
}
catch (Exception e) {
latch.countDown();
throw new RuntimeException(e);
}

assertEquals("new content", newContentStr);
latch.countDown();
});
});
latch.await();
Expand Down Expand Up @@ -720,6 +722,7 @@ public void canWriteDataToFile() throws InterruptedException {
}

assertEquals("Rewrite State!", newContentStr);
latch.countDown();
}
catch (Exception e) {
latch.countDown();
Expand Down

0 comments on commit 3984592

Please sign in to comment.