Search in sources :

Example 36 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class ResolveGeogigDirTest method test.

@Test
public void test() throws Exception {
    File workingDir = tmpFolder.newFolder("fakeWorkingDir");
    File fakeRepo = new File(workingDir, ".geogig");
    fakeRepo.mkdirs();
    Platform platform = mock(Platform.class);
    when(platform.pwd()).thenReturn(workingDir);
    URL resolvedRepoDir = new ResolveGeogigDir(platform).call().get();
    assertEquals(fakeRepo.toURI().toURL(), resolvedRepoDir);
    workingDir = new File(new File(workingDir, "subdir1"), "subdir2");
    workingDir.mkdirs();
    when(platform.pwd()).thenReturn(workingDir);
    resolvedRepoDir = new ResolveGeogigDir(platform).call().get();
    assertEquals(fakeRepo.toURI().toURL(), resolvedRepoDir);
    when(platform.pwd()).thenReturn(tmpFolder.getRoot());
    assertFalse(new ResolveGeogigDir(platform).call().isPresent());
}
Also used : Platform(org.locationtech.geogig.api.Platform) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 37 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class WorkingTree method insert.

public void insert(final String treePath, @SuppressWarnings("rawtypes") final FeatureSource source, final Query query, ProgressListener listener) {
    final NodeRef treeRef = findOrCreateTypeTree(treePath, source);
    Long collectionSize = null;
    try {
        // try for a fast count
        int count = source.getCount(Query.ALL);
        if (count > -1) {
            collectionSize = Long.valueOf(count);
        }
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    final int nFetchThreads;
    {
        // maxFeatures is assumed to be supported by all data sources, so supportsPaging depends
        // only on offset being supported
        boolean supportsPaging = source.getQueryCapabilities().isOffsetSupported();
        if (supportsPaging) {
            Platform platform = context.platform();
            int availableProcessors = platform.availableProcessors();
            nFetchThreads = Math.max(2, availableProcessors / 2);
        } else {
            nFetchThreads = 1;
        }
    }
    final ExecutorService executorService = Executors.newFixedThreadPool(2 + nFetchThreads, new ThreadFactoryBuilder().setNameFormat("WorkingTree-tree-builder-%d").build());
    listener.started();
    Stopwatch sw = Stopwatch.createStarted();
    final RevTree origTree = indexDatabase.getTree(treeRef.objectId());
    Platform platform = context.platform();
    RevTreeBuilder2 builder = new RevTreeBuilder2(indexDatabase, origTree, treeRef.getMetadataId(), platform, executorService);
    List<Future<Integer>> insertBlobsFuture = insertBlobs(source, query, executorService, listener, collectionSize, nFetchThreads, builder);
    RevTree newFeatureTree;
    try {
        long insertedCount = 0;
        for (Future<Integer> f : insertBlobsFuture) {
            insertedCount += f.get().longValue();
        }
        sw.stop();
        listener.setDescription(insertedCount + " distinct features inserted in " + sw);
        listener.setDescription("Building final tree...");
        sw.reset().start();
        newFeatureTree = builder.build();
        listener.setDescription(String.format("%d features tree built in %s", newFeatureTree.size(), sw.stop()));
        listener.complete();
    } catch (Exception e) {
        throw Throwables.propagate(Throwables.getRootCause(e));
    } finally {
        executorService.shutdown();
    }
    ObjectId newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(treePath).setMetadataId(treeRef.getMetadataId()).setToIndex(true).setTree(newFeatureTree).call();
    updateWorkHead(newTree);
}
Also used : Platform(org.locationtech.geogig.api.Platform) ObjectId(org.locationtech.geogig.api.ObjectId) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) IOException(java.io.IOException) NodeRef(org.locationtech.geogig.api.NodeRef) ExecutorService(java.util.concurrent.ExecutorService) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) Future(java.util.concurrent.Future) RevTree(org.locationtech.geogig.api.RevTree)

Example 38 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class WorkingTreeInsertHelper method createBuilder.

private RevTreeBuilder2 createBuilder(String treePath, FeatureType type) {
    final NodeRef treeRef = findOrCreateTree(treePath, type);
    final ObjectId treeId = treeRef.objectId();
    final RevTree origTree = indexDatabase.getTree(treeId);
    ObjectId defaultMetadataId = treeRef.getMetadataId();
    RevTreeBuilder2 builder;
    Platform platform = context.platform();
    builder = new RevTreeBuilder2(indexDatabase, origTree, defaultMetadataId, platform, executorService);
    return builder;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) Platform(org.locationtech.geogig.api.Platform) ObjectId(org.locationtech.geogig.api.ObjectId) RevTree(org.locationtech.geogig.api.RevTree)

Example 39 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class MongoCommitOpTest method createInjector.

@Override
protected Context createInjector() {
    File workingDirectory;
    try {
        workingDirectory = mockWorkingDirTempFolder.getRoot();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    Platform testPlatform = new TestPlatform(workingDirectory);
    return Guice.createInjector(Modules.override(new GeogigModule()).with(new MongoTestStorageModule(), new TestModule(testPlatform))).getInstance(Context.class);
}
Also used : TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule)

Example 40 with Platform

use of org.locationtech.geogig.api.Platform in project GeoGig by boundlessgeo.

the class MongoConflictsTest method createInjector.

@Override
protected Context createInjector() {
    File workingDirectory;
    try {
        workingDirectory = mockWorkingDirTempFolder.getRoot();
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    Platform testPlatform = new TestPlatform(workingDirectory);
    return Guice.createInjector(Modules.override(new GeogigModule()).with(new MongoTestStorageModule(), new TestModule(testPlatform))).getInstance(Context.class);
}
Also used : TestPlatform(org.locationtech.geogig.api.TestPlatform) Platform(org.locationtech.geogig.api.Platform) TestPlatform(org.locationtech.geogig.api.TestPlatform) File(java.io.File) GeogigModule(org.locationtech.geogig.di.GeogigModule)

Aggregations

Platform (org.locationtech.geogig.api.Platform)41 File (java.io.File)27 TestPlatform (org.locationtech.geogig.api.TestPlatform)10 Before (org.junit.Before)7 Context (org.locationtech.geogig.api.Context)7 GeogigModule (org.locationtech.geogig.di.GeogigModule)6 GeoGIG (org.locationtech.geogig.api.GeoGIG)5 ObjectId (org.locationtech.geogig.api.ObjectId)5 Repository (org.locationtech.geogig.repository.Repository)5 IOException (java.io.IOException)4 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)4 UpdateSymRef (org.locationtech.geogig.api.plumbing.UpdateSymRef)4 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)3 DefaultPlatform (org.locationtech.geogig.api.DefaultPlatform)3 MemoryModule (org.locationtech.geogig.api.MemoryModule)3 RevCommit (org.locationtech.geogig.api.RevCommit)3 RevTree (org.locationtech.geogig.api.RevTree)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URL (java.net.URL)2 UnsupportedTerminal (jline.UnsupportedTerminal)2