mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-14 20:24:53 +00:00
Merge pull request #20 from overleaf/df-and-timeout
Improved disk space calculation and increased postback timeout
This commit is contained in:
commit
bdc699991f
5 changed files with 38 additions and 18 deletions
|
@ -12,6 +12,7 @@ import java.nio.file.Paths;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static uk.ac.ic.wlgitbridge.util.Util.deleteInDirectoryApartFrom;
|
||||
|
||||
|
@ -22,10 +23,16 @@ public class FSGitRepoStore implements RepoStore {
|
|||
|
||||
private final String repoStorePath;
|
||||
private final File rootDirectory;
|
||||
private final Function<File, Long> fsSizer;
|
||||
|
||||
public FSGitRepoStore(String repoStorePath) {
|
||||
this(repoStorePath, d -> d.getTotalSpace() - d.getFreeSpace());
|
||||
}
|
||||
|
||||
public FSGitRepoStore(String repoStorePath, Function<File, Long> fsSizer) {
|
||||
this.repoStorePath = repoStorePath;
|
||||
rootDirectory = initRootGitDirectory(repoStorePath);
|
||||
this.fsSizer = fsSizer;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -54,7 +61,7 @@ public class FSGitRepoStore implements RepoStore {
|
|||
|
||||
@Override
|
||||
public long totalSize() {
|
||||
return FileUtils.sizeOfDirectory(rootDirectory);
|
||||
return fsSizer.apply(rootDirectory);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,7 +35,7 @@ public class PostbackPromise {
|
|||
try {
|
||||
while (!received) {
|
||||
try {
|
||||
if (!cond.await(30, TimeUnit.SECONDS)) {
|
||||
if (!cond.await(60, TimeUnit.SECONDS)) {
|
||||
throw new PostbackTimeoutException();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
|
|
|
@ -13,7 +13,7 @@ public class PostbackTimeoutException extends SevereSnapshotPostException {
|
|||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "timeout";
|
||||
return "timeout (60s)";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
package uk.ac.ic.wlgitbridge.bridge.repo;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import uk.ac.ic.wlgitbridge.util.Files;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by winston on 23/08/2016.
|
||||
|
@ -52,16 +49,30 @@ public class FSGitRepoStoreTest {
|
|||
public void testPurgeNonexistentProjects() {
|
||||
File toDelete = new File(repoStore.getRootDirectory(), "idontexist");
|
||||
File wlgb = new File(repoStore.getRootDirectory(), ".wlgb");
|
||||
Assert.assertTrue(toDelete.exists());
|
||||
Assert.assertTrue(wlgb.exists());
|
||||
assertTrue(toDelete.exists());
|
||||
assertTrue(wlgb.exists());
|
||||
repoStore.purgeNonexistentProjects(Arrays.asList("proj1", "proj2"));
|
||||
Assert.assertFalse(toDelete.exists());
|
||||
Assert.assertTrue(wlgb.exists());
|
||||
assertFalse(toDelete.exists());
|
||||
assertTrue(wlgb.exists());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTotalSize() {
|
||||
assertEquals(31860, repoStore.totalSize());
|
||||
public void totalSizeShouldChangeWhenFilesAreCreatedAndDeleted()
|
||||
throws IOException {
|
||||
long old = repoStore.totalSize();
|
||||
File temp = new File(repoStore.getRootDirectory(), "__temp.txt");
|
||||
try (
|
||||
OutputStream out = new FileOutputStream(
|
||||
temp
|
||||
)
|
||||
) {
|
||||
out.write(new byte[16 * 1024 * 1024]);
|
||||
}
|
||||
long new_ = repoStore.totalSize();
|
||||
assertTrue(new_ > old);
|
||||
assertTrue(temp.delete());
|
||||
long new__ = repoStore.totalSize();
|
||||
assertTrue(new__ < new_);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -69,10 +80,10 @@ public class FSGitRepoStoreTest {
|
|||
long beforeSize = repoStore.totalSize();
|
||||
InputStream zipped = repoStore.bzip2Project("proj1");
|
||||
repoStore.remove("proj1");
|
||||
Assert.assertTrue(beforeSize > repoStore.totalSize());
|
||||
assertTrue(beforeSize > repoStore.totalSize());
|
||||
repoStore.unbzip2Project("proj1", zipped);
|
||||
Assert.assertEquals(beforeSize, repoStore.totalSize());
|
||||
Assert.assertTrue(
|
||||
assertEquals(beforeSize, repoStore.totalSize());
|
||||
assertTrue(
|
||||
Files.contentsAreEqual(
|
||||
original,
|
||||
repoStore.getRootDirectory()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package uk.ac.ic.wlgitbridge.bridge.swap.job;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
@ -43,7 +44,8 @@ public class SwapJobImplTest {
|
|||
FSGitRepoStoreTest.makeTempRepoDir(
|
||||
tmpFolder,
|
||||
"repostore"
|
||||
).getAbsolutePath()
|
||||
).getAbsolutePath(),
|
||||
FileUtils::sizeOfDirectory
|
||||
);
|
||||
dbStore = new SqliteDBStore(tmpFolder.newFile());
|
||||
dbStore.setLatestVersionForProject("proj1", 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue