diff options
author | Saša Živkov <sasa.zivkov@sap.com> | 2016-03-22 17:23:53 +0100 |
---|---|---|
committer | Saša Živkov <sasa.zivkov@sap.com> | 2016-03-22 17:26:46 +0100 |
commit | b72fc2b4942d45f4e8317821be0c3eb470b1688f (patch) | |
tree | 81e49fe8be8b8d26f0fdb5073af47df2404a56ce /org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs | |
parent | 8efdaaf99119ca86f91f1acd9b62a5e305155772 (diff) | |
download | jgit-b72fc2b4942d45f4e8317821be0c3eb470b1688f.tar.gz jgit-b72fc2b4942d45f4e8317821be0c3eb470b1688f.zip |
Make the FileLfsRepository thread safe
The FileLfsRepository.out member could have been accessed from multiple
threads which would corrupt the content.
Don't store the AtomicObjectOutputStream in the FileLfsRepository.out but
move it to the ObjectUploadListener which is instantiated per-request.
Add a parallel upload test.
Change-Id: I62298630e99c46b500d376843ffcde934436215b
Signed-off-by: Saša Živkov <sasa.zivkov@sap.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs')
-rw-r--r-- | org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/UploadTest.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/UploadTest.java b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/UploadTest.java index 35bf09b0c1..1fb91bd29d 100644 --- a/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/UploadTest.java +++ b/org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/UploadTest.java @@ -51,6 +51,13 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import org.eclipse.jgit.lfs.lib.AnyLongObjectId; import org.eclipse.jgit.lfs.lib.LongObjectId; @@ -98,4 +105,36 @@ public class UploadTest extends LfsServerTest { assertEquals("expected object length " + Files.size(f), Files.size(f), repository.getSize(id)); } + + @Test + public void testParallelUploads() throws Exception { + int count = 10; + List<Path> paths = new ArrayList<>(count); + + for (int i = 0; i < count; i++) { + Path f = Paths.get(getTempDirectory().toString(), + "largeRandomFile_" + i); + createPseudoRandomContentFile(f, 1 * MiB); + paths.add(f); + } + + final CyclicBarrier barrier = new CyclicBarrier(count); + + ExecutorService e = Executors.newFixedThreadPool(count); + try { + for (final Path p : paths) { + e.submit(new Callable<Void>() { + @Override + public Void call() throws Exception { + barrier.await(); + putContent(p); + return null; + } + }); + } + } finally { + e.shutdown(); + e.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); + } + } } |