@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { if (o != null && o instanceof JGitFileSystemProxy) { o = ((JGitFileSystemProxy) o).getRealJGitFileSystem(); } else { return false; } } JGitFileSystemImpl that = (JGitFileSystemImpl) o; if (!name.equals(that.name)) { return false; } return true; }
public JGitFileSystem get(String fsName) { Supplier<JGitFileSystem> memoizedSupplier = memoizedSuppliers.get(fsName); if (memoizedSupplier != null) { return new JGitFileSystemProxy(fsName, memoizedSupplier); } else if (fileSystemsSuppliers.get(fsName) != null) { Supplier<JGitFileSystem> newMemoizedSupplier = createMemoizedSupplier(fsName, fileSystemsSuppliers.get(fsName)); return new JGitFileSystemProxy(fsName, newMemoizedSupplier); } return null; }
@Test public void proxyTest() { final URI originRepo = URI.create("git://encoding-origin-name"); final JGitFileSystem origin = (JGitFileSystem) provider.newFileSystem(originRepo, Collections.emptyMap()); assertTrue(origin instanceof JGitFileSystemProxy); JGitFileSystemProxy proxy = (JGitFileSystemProxy) origin; JGitFileSystem realJGitFileSystem = proxy.getRealJGitFileSystem(); assertTrue(realJGitFileSystem instanceof JGitFileSystemImpl); assertTrue(proxy.equals(realJGitFileSystem)); assertTrue(realJGitFileSystem.equals(proxy)); } }
final JGitFileSystemImpl realInstanceFs1 = (JGitFileSystemImpl) fs1.getRealJGitFileSystem(); assertThat(fsCache.getFileSystems()).contains(fs1.getName()); assertThat(fsCache.getFileSystems()).contains(fs2.getName()); assertThat(fsCache.getFileSystems()).contains(fs3.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs3.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).doesNotContain(fs1.getName()); JGitFileSystemImpl anotherInstanceOfFs1 = (JGitFileSystemImpl) anotherInstanceOfFs1Proxy.getRealJGitFileSystem(); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs1.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs3.getName());
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }
final JGitFileSystemImpl realInstanceFs1 = (JGitFileSystemImpl) fs1.getRealJGitFileSystem(); assertThat(fsCache.getFileSystems()).contains(fs1.getName()); assertThat(fsCache.getFileSystems()).contains(fs2.getName()); assertThat(fsCache.getFileSystems()).contains(fs3.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs3.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).doesNotContain(fs1.getName()); JGitFileSystemImpl anotherInstanceOfFs1 = (JGitFileSystemImpl) anotherInstanceOfFs1Proxy.getRealJGitFileSystem(); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs1.getName()); assertThat(cacheInfo.memoizedFileSystemsCacheKeys()).contains(fs3.getName());
@Test public void testDeleteShouldRemoveEmptyParentDir() throws IOException { final URI doraRepo = URI.create("git://parentDir/dora-repo"); FileSystem doraFS = provider.newFileSystem(doraRepo, EMPTY_ENV); final File doraRepoDir = ((JGitFileSystemProxy) doraFS).getGit().getRepository().getDirectory(); final File parentDir = doraRepoDir.getParentFile(); final File gitProviderDir = provider.getGitRepoContainerDir(); final URI doraRepo1 = URI.create("git://parentDir/dora-repo1"); FileSystem doraFS1 = provider.newFileSystem(doraRepo1, EMPTY_ENV); final File dora1RepoDir = ((JGitFileSystemProxy) doraFS1).getGit().getRepository().getDirectory(); final File parentDir1 = doraRepoDir.getParentFile(); assertEquals(parentDir, parentDir1); provider.delete(doraFS.getPath(null)); assertFalse(doraRepoDir.exists()); assertTrue(parentDir.exists()); assertTrue(gitProviderDir.exists()); provider.delete(doraFS1.getPath(null)); assertFalse(dora1RepoDir.exists()); assertFalse(parentDir1.exists()); assertTrue(gitProviderDir.exists()); }
@Test public void testUsingProvidedPath() { final URI newRepo = URI.create("git://repo-name"); JGitFileSystemProxy fileSystem = (JGitFileSystemProxy) provider.newFileSystem(newRepo, EMPTY_ENV); //no infra created due to lazy loading nature of our FS String[] names = tempDir.list(); assertThat(names).isEmpty(); String[] repos = new File(tempDir, dirPathName).list(); assertThat(repos).isNull(); //FS created fileSystem.getRealJGitFileSystem(); names = tempDir.list(); assertThat(names).contains(dirPathName); repos = new File(tempDir, dirPathName).list(); assertThat(repos).contains("repo-name.git"); } }
@Test public void proxyTest() { final URI originRepo = URI.create("git://encoding-origin-name"); final JGitFileSystem origin = (JGitFileSystem) provider.newFileSystem(originRepo, Collections.emptyMap()); assertTrue(origin instanceof JGitFileSystemProxy); JGitFileSystemProxy proxy = (JGitFileSystemProxy) origin; JGitFileSystem realJGitFileSystem = proxy.getRealJGitFileSystem(); assertTrue(realJGitFileSystem instanceof JGitFileSystemImpl); assertTrue(proxy.equals(realJGitFileSystem)); assertTrue(realJGitFileSystem.equals(proxy)); } }
@Test public void testUsingProvidedPath() { final URI newRepo = URI.create("git://repo-name"); JGitFileSystemProxy fileSystem = (JGitFileSystemProxy) provider.newFileSystem(newRepo, EMPTY_ENV); //no infra created due to lazy loading nature of our FS String[] names = tempDir.list(); assertThat(names).isEmpty(); String[] repos = new File(tempDir, dirPathName).list(); assertThat(repos).isNull(); //FS created fileSystem.getRealJGitFileSystem(); names = tempDir.list(); assertThat(names).contains(dirPathName); repos = new File(tempDir, dirPathName).list(); assertThat(repos).contains("repo-name.git"); } }
@BeforeClass public static void setup() throws IOException { assertTrue(PriorityDisposableRegistry.getDisposables().contains(ioService)); path = CommonIOServiceDotFileTest.createTempDirectory(); System.setProperty("org.uberfire.nio.git.dir", path.getAbsolutePath()); final URI newRepo = URI.create("git://amend-repo-test"); fs1 = ioService.newFileSystem(newRepo, new HashMap<>()); jgitFs1 = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs1).getRealJGitFileSystem(); Path init = ioService.get(URI.create("git://amend-repo-test/init.file")); ioService.write(init, "setupFS!"); }
@Test public void resolveByRepositoryTest() { JGitFileSystem fsSimpleName = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://repo"), EMPTY_ENV)).getRealJGitFileSystem(); JGitFileSystemProvider.RepositoryResolverImpl<Object> objectRepositoryResolver = provider.new RepositoryResolverImpl<>(); assertEquals(fsSimpleName, objectRepositoryResolver.resolveFileSystem(fsSimpleName.getGit().getRepository())); JGitFileSystem fsComposedName1 = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://user1/dora"), EMPTY_ENV)).getRealJGitFileSystem(); assertEquals(fsComposedName1, objectRepositoryResolver.resolveFileSystem(fsComposedName1.getGit().getRepository())); }
@BeforeClass public static void setup() throws IOException { assertTrue(PriorityDisposableRegistry.getDisposables().contains(ioService)); path = CommonIOServiceDotFileTest.createTempDirectory(); System.setProperty("org.uberfire.nio.git.dir", path.getAbsolutePath()); final URI newRepo = URI.create("git://amend-repo-test"); fs1 = ioService.newFileSystem(newRepo, new HashMap<>()); jgitFs1 = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs1).getRealJGitFileSystem(); Path init = ioService.get(URI.create("git://amend-repo-test/init.file")); ioService.write(init, "setupFS!"); }
@Test public void resolveByRepositoryTest() { JGitFileSystem fsSimpleName = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://repo"), EMPTY_ENV)).getRealJGitFileSystem(); JGitFileSystemProvider.RepositoryResolverImpl<Object> objectRepositoryResolver = provider.new RepositoryResolverImpl<>(); assertEquals(fsSimpleName, objectRepositoryResolver.resolveFileSystem(fsSimpleName.getGit().getRepository())); JGitFileSystem fsComposedName1 = ((JGitFileSystemProxy) provider.newFileSystem(URI.create("git://user1/dora"), EMPTY_ENV)).getRealJGitFileSystem(); assertEquals(fsComposedName1, objectRepositoryResolver.resolveFileSystem(fsComposedName1.getGit().getRepository())); }
final JGitFileSystemProxy fsProxy = (JGitFileSystemProxy) provider.newFileSystem(newRepo, EMPTY_ENV); JGitFileSystem fs = fsProxy.getRealJGitFileSystem();
final JGitFileSystemProxy fsProxy = (JGitFileSystemProxy) provider.newFileSystem(newRepo, EMPTY_ENV); JGitFileSystem fs = fsProxy.getRealJGitFileSystem();
cache.memoizedSuppliers.size()); ((JGitFileSystemProxy) cache.get("fs1")).getRealJGitFileSystem(); cache.addSupplier("fs2", fs2Supplier); ((JGitFileSystemProxy) cache.get("fs2")).getRealJGitFileSystem(); fs3Supplier); ((JGitFileSystemProxy) cache.get("fs3")).getRealJGitFileSystem(); cache.memoizedSuppliers.size()); ((JGitFileSystemProxy) cache.get("fs2")).getRealJGitFileSystem(); times(1)).get(); ((JGitFileSystemProxy) cache.get("fs3")).getRealJGitFileSystem(); times(1)).get(); ((JGitFileSystemProxy) cache.get("fs1")).getRealJGitFileSystem();
cache.memoizedSuppliers.size()); ((JGitFileSystemProxy) cache.get("fs1")).getRealJGitFileSystem(); cache.addSupplier("fs2", fs2Supplier); ((JGitFileSystemProxy) cache.get("fs2")).getRealJGitFileSystem(); fs3Supplier); ((JGitFileSystemProxy) cache.get("fs3")).getRealJGitFileSystem(); cache.memoizedSuppliers.size()); ((JGitFileSystemProxy) cache.get("fs2")).getRealJGitFileSystem(); times(1)).get(); ((JGitFileSystemProxy) cache.get("fs3")).getRealJGitFileSystem(); times(1)).get(); ((JGitFileSystemProxy) cache.get("fs1")).getRealJGitFileSystem();
fs1Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs1).getRealJGitFileSystem(); Path init = ioService.get(URI.create("git://amend-repo-test/init.file")); ioService.write(init, "true"); }}); fs2Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs2).getRealJGitFileSystem(); init = ioService.get(URI.create("git://check-amend-repo-test/init.file")); ioService.write(init, "true"); }}); fs3Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs3).getRealJGitFileSystem(); init = ioService.get(URI.create("git://check-amend-repo-test-2/init.file")); ioService.write(init,
fs1Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs1).getRealJGitFileSystem(); Path init = ioService.get(URI.create("git://amend-repo-test/init.file")); ioService.write(init, "true"); }}); fs2Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs2).getRealJGitFileSystem(); init = ioService.get(URI.create("git://check-amend-repo-test/init.file")); ioService.write(init, "true"); }}); fs3Batch = (JGitFileSystemImpl) ((JGitFileSystemProxy) fs3).getRealJGitFileSystem(); init = ioService.get(URI.create("git://check-amend-repo-test-2/init.file")); ioService.write(init,