/** * Obtains the repository for the current directory or creates a new one and returns it if no * repository can be found on the current directory. * * @return the existing or newly created repository, never {@code null} * @throws RuntimeException if the repository cannot be created at the current directory * @see InitOp */ public Repository getOrCreateRepository() { if (repository == null) { repository = command(InitOp.class).call(); checkState(repository != null, "Repository shouldn't be null as we checked it didn't exist before calling init"); } return repository; }
/** * Obtains the repository for the current directory or creates a new one and returns it if no * repository can be found on the current directory. * * @return the existing or newly created repository, never {@code null} * @throws RuntimeException if the repository cannot be created at the current directory * @see InitOp */ public Repository getOrCreateRepository() { if (repository == null) { try { repository = command(InitOp.class).call(); checkState(repository != null, "Repository shouldn't be null as we checked it didn't exist before calling init"); } catch (Exception e) { throw Throwables.propagate(e); } } return repository; }
@Test public void testNullWorkingDir() { when(platform.pwd()).thenReturn(null); exception.expect(IllegalStateException.class); init.call(); when(platform.pwd()).thenReturn(workingDir); }
@Test public void testNullWorkingDir() { when(platform.pwd()).thenReturn(null); exception.expect(IllegalStateException.class); init.call(); when(platform.pwd()).thenReturn(workingDir); }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
@Test public void testReinitializeExistingRepoFromInsideASubdirectory() throws Exception { testCreateNewRepo(); File subDir = new File(new File(workingDir, "subdir1"), "subdir2"); assertTrue(subDir.mkdirs()); when(platform.pwd()).thenReturn(subDir); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); } }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
@Test public void testCreateNewRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); verify(injector, times(1)).repository(); verify(mockUpdateRef, times(1)).setName(eq(Ref.MASTER)); verify(mockUpdateRef, times(1)).setName(eq(Ref.WORK_HEAD)); verify(mockUpdateRef, times(1)).setName(eq(Ref.STAGE_HEAD)); verify(mockUpdateRef, times(1)).setNewValue(eq(ObjectId.NULL)); verify(mockUpdateRef, times(2)).setNewValue(eq(RevTree.EMPTY_TREE_ID)); verify(mockUpdateRef, times(3)).setReason(anyString()); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).setName(eq(Ref.HEAD)); verify(mockUpdateSymRef, times(1)).setNewValue(eq(Ref.MASTER)); verify(mockUpdateSymRef, times(1)).call(); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
public TestData init(final String userName, final String userEmail) { repo.command(InitOp.class).call(); config("user.name", userName).config("user.email", userEmail); return this; }
public TestData init(final String userName, final String userEmail) { repo.command(InitOp.class).call(); config("user.name", userName).config("user.email", userEmail); return this; }
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
@Test public void testReinitializeExistingRepo() throws Exception { when(injector.repository()).thenReturn(mockRepo); Optional<Ref> absent = Optional.absent(); when(mockRefParse.call()).thenReturn(absent); Repository created = init.call(); assertSame(mockRepo, created); verify(mockUpdateRef, times(3)).call(); verify(mockUpdateSymRef, times(1)).call(); assertTrue(new File(workingDir, ".geogig").exists()); assertTrue(new File(workingDir, ".geogig").isDirectory()); Ref master = new Ref(Ref.MASTER, RevObjectTestSupport.hashString("hash me")); when(mockRefParse.call()).thenReturn(Optional.of(master)); Context injector = mock(Context.class); when(injector.command(eq(RefParse.class))).thenReturn(mockRefParse); when(injector.platform()).thenReturn(platform); when(injector.repository()).thenReturn(mockRepo); init.setContext(injector); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); assertNotNull(init.call()); verify(platform, atLeastOnce()).pwd(); assertTrue(ResolveGeogigURI.lookup(platform.pwd()).isPresent()); verify(injector, never()).command(eq(UpdateRef.class)); verify(injector, never()).command(eq(UpdateSymRef.class)); assertEquals(RevTree.EMPTY, objectDatabase.get(RevTree.EMPTY_TREE_ID)); }
public TestData newRepo(@NonNull String name) { Preconditions.checkState(!repos.containsKey(name)); URI uri; try { uri = tmp.newFolder(name).toURI(); } catch (IOException e) { throw new RuntimeException(e); } Hints hints = Hints.readWrite().uri(uri); hints.set(Hints.REPOSITORY_NAME, name); Context context = GlobalContextBuilder.builder().build(hints); Repository repo = context.command(InitOp.class).call(); try { repo.open(); TestData repoWorker = new TestData(repo); repoWorker.init(); repos.put(name, repoWorker); return getRepo(name); } catch (Exception e) { throw new RuntimeException(e); } }
private void create(final RepositoryInfo repoInfo) { URI repoURI = repoInfo.getLocation(); RepositoryResolver resolver = RepositoryResolver.lookup(repoURI); if (!resolver.repoExists(repoURI)) { Hints hints = new Hints(); hints.set(Hints.REPOSITORY_URL, repoURI); hints.set(Hints.REPOSITORY_NAME, repoInfo.getRepoName()); Context context = GlobalContextBuilder.builder().build(hints); GeoGIG geogig = new GeoGIG(context); try { Repository repository = geogig.command(InitOp.class).call(); Preconditions.checkState(repository != null); } finally { geogig.close(); } } }
newRepo = command.call();
newRepo = command.call();
@Before public void beforeTest() throws Exception { File workingDirectory = tmp.newFolder("repo"); File userHomeDirectory = tmp.newFolder("home"); TestPlatform platform = new TestPlatform(workingDirectory); platform.setUserHome(userHomeDirectory); GlobalContextBuilder.builder(new TestContextBuilder(platform)); context = GlobalContextBuilder.builder().build(new Hints().platform(platform)); GeoGIG repo = new GeoGIG(context); repo.command(InitOp.class).call(); repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.name") .setValue("gabriel").call(); repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.email") .setValue("gabriel@roldan.example.com").call(); store = new GeoGigDataStore(repo.getRepository()); store.createSchema(pointType); editThreads = Executors.newFixedThreadPool(writeThreadCount, new ThreadFactoryBuilder().setNameFormat("edit-thread-%d").build()); readThreads = Executors.newFixedThreadPool(readThreadCount, new ThreadFactoryBuilder().setNameFormat("read-thread-%d").build()); initialCommitCount = copyOf(context.command(LogOp.class).call()).size(); // reset Insert counter each scenario CONCURRENT_INSERT_COUNT.set(0); // clear ReadTask counts each scenario READ_COUNT_LIST.clear(); }
@Before public void beforeTest() throws Exception { File workingDirectory = tmp.newFolder("repo"); File userHomeDirectory = tmp.newFolder("home"); TestPlatform platform = new TestPlatform(workingDirectory); platform.setUserHome(userHomeDirectory); GlobalContextBuilder.builder(new TestContextBuilder(platform)); context = GlobalContextBuilder.builder().build(new Hints().platform(platform)); GeoGIG repo = new GeoGIG(context); repo.command(InitOp.class).call(); repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.name") .setValue("gabriel").call(); repo.command(ConfigOp.class).setAction(ConfigAction.CONFIG_SET).setName("user.email") .setValue("gabriel@roldan.example.com").call(); store = new GeoGigDataStore(repo.getRepository()); store.createSchema(pointType); editThreads = Executors.newFixedThreadPool(writeThreadCount, new ThreadFactoryBuilder().setNameFormat("edit-thread-%d").build()); readThreads = Executors.newFixedThreadPool(readThreadCount, new ThreadFactoryBuilder().setNameFormat("read-thread-%d").build()); initialCommitCount = copyOf(context.command(LogOp.class).call()).size(); // reset Insert counter each scenario CONCURRENT_INSERT_COUNT.set(0); // clear ReadTask counts each scenario READ_COUNT_LIST.clear(); }
private Repository initRepo(String repoName) throws IOException { File workingDirectory = tmp.newFolder(repoName); TestPlatform platform = new TestPlatform(workingDirectory, userHomeDirectry); GlobalContextBuilder.builder(new TestContextBuilder(platform)); Context context = GlobalContextBuilder.builder().build(new Hints().platform(platform)); GeoGIG geogig = new GeoGIG(context); geogig.command(InitOp.class).call(); geogig.command(ConfigOp.class).setAction(ConfigOp.ConfigAction.CONFIG_SET). setName("user.name").setValue("geogig_test").call(); geogig.command(ConfigOp.class).setAction(ConfigOp.ConfigAction.CONFIG_SET). setName("user.email").setValue("geogig_test@geogig.org").call(); return geogig.getRepository(); }
private Repository initRepo(String repoName) throws IOException { File workingDirectory = tmp.newFolder(repoName); TestPlatform platform = new TestPlatform(workingDirectory, userHomeDirectry); GlobalContextBuilder.builder(new TestContextBuilder(platform)); Context context = GlobalContextBuilder.builder().build(new Hints().platform(platform)); GeoGIG geogig = new GeoGIG(context); geogig.command(InitOp.class).call(); geogig.command(ConfigOp.class).setAction(ConfigOp.ConfigAction.CONFIG_SET). setName("user.name").setValue("geogig_test").call(); geogig.command(ConfigOp.class).setAction(ConfigOp.ConfigAction.CONFIG_SET). setName("user.email").setValue("geogig_test@geogig.org").call(); return geogig.getRepository(); }