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());
}
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);
}
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;
}
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);
}
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);
}
Aggregations