@Override public void configure(SyncStorage source, Iterator<SyncFilter> filters, SyncStorage target) { super.configure(source, filters, target); if (config.getLocalCacheRoot() == null) throw new ConfigurationException("must specify a cache root"); File cacheRoot = new File(config.getLocalCacheRoot()); if (!cacheRoot.exists() || !cacheRoot.isDirectory() || !cacheRoot.canWrite() || cacheRoot.list().length != 0) throw new ConfigurationException(cacheRoot + " is not a writable empty directory"); // split plugin chain for each side of the cache (source -> cache and cache -> target) List<SyncFilter> filtersBeforeCache = new ArrayList<>(); List<SyncFilter> filtersAfterCache = new ArrayList<>(); boolean beforeCache = true; while (filters.hasNext()) { SyncFilter filter = filters.next(); if (filter == this) beforeCache = false; else if (beforeCache) filtersBeforeCache.add(filter); else filtersAfterCache.add(filter); } FilesystemConfig cacheConfig = new FilesystemConfig(); cacheConfig.setPath(config.getLocalCacheRoot()); cacheTarget = new FilesystemStorage(); cacheTarget.setConfig(cacheConfig); cacheTarget.setOptions(options); cacheTarget.configure(source, filtersBeforeCache.iterator(), cacheTarget); cacheSource = new FilesystemStorage(); cacheSource.setConfig(cacheConfig); cacheSource.setOptions(options); cacheSource.configure(cacheSource, filtersAfterCache.iterator(), target); }
@Test public void testFilesystem() { final File tempDir = new File("/tmp/ecs-sync-filesystem-test"); // File.createTempFile("ecs-sync-filesystem-test", "dir"); tempDir.mkdir(); tempDir.deleteOnExit(); if (!tempDir.exists() || !tempDir.isDirectory()) throw new RuntimeException("unable to make temp dir"); FilesystemConfig filesystemConfig = new FilesystemConfig(); filesystemConfig.setPath(tempDir.getPath()); filesystemConfig.setStoreMetadata(true); multiEndToEndTest(filesystemConfig, new TestConfig(), false); new File(tempDir, ObjectMetadata.METADATA_DIR).delete(); // delete this so the temp dir can go away }
@Test public void testSingleFile() throws Exception { String name = "single-file-test"; File sFile = new File(sourceDir, name); File tFile = new File(targetDir, name); int size = 100 * 1024; StreamUtil.copy(new RandomInputStream(size), new FileOutputStream(sFile), size); FilesystemConfig sConfig = new FilesystemConfig(); sConfig.setPath(sFile.getAbsolutePath()); FilesystemConfig tConfig = new FilesystemConfig(); tConfig.setPath(tFile.getAbsolutePath()); SyncConfig syncConfig = new SyncConfig().withSource(sConfig).withTarget(tConfig); EcsSync sync = new EcsSync(); sync.setSyncConfig(syncConfig); sync.run(); Assert.assertArrayEquals(Files.readAllBytes(sFile.toPath()), Files.readAllBytes(tFile.toPath())); } }
fsConfig.setPath(sourceDir.getPath()); TestConfig testConfig = new TestConfig().withReadData(true).withDiscardData(false); PreserveFileAttributesConfig preserveConfig = new PreserveFileAttributesConfig(); Assert.assertEquals(0, sync.getStats().getObjectsFailed()); fsConfig.setPath(targetDir.getPath());
sourceConfig.setPath(tempPath.toString()); TestConfig testConfig = new TestConfig(); SyncOptions options = new SyncOptions().withThreadCount(2).withRememberFailed(true);
@Test public void testExcludeFilter() throws Exception { Path file = Paths.get("."); FilesystemConfig fsConfig = new FilesystemConfig(); fsConfig.setPath(file.toString()); fsConfig.setExcludedPaths(new String[]{"(.*/)?\\.[^/]*", "(.*/)?[^/]*foo[^/]*", "(.*/)?[^/]*\\.bin"}); FilesystemStorage storage = new FilesystemStorage(); storage.setConfig(fsConfig); storage.configure(storage, null, null); DirectoryStream.Filter<Path> filter = storage.getFilter(); String[] positiveTests = new String[]{"bar.txt", "a.out", "this has spaces", "n.o.t.h.i.n.g"}; for (String test : positiveTests) { Assert.assertTrue("filter should have accepted " + test, filter.accept(file.resolve(test))); } String[] negativeTests = new String[]{".svn", ".snapshots", ".f.o.o", "foo.txt", "ffoobar", "mywarez.bin", "in.the.round.bin"}; for (String test : negativeTests) { Assert.assertFalse("filter should have rejected " + test, filter.accept(file.resolve(test))); } }
@Test public void testSingleFileToFilesystem() throws Exception { NfsConfig sourceConfig = getNfsConfig(nfs); sourceConfig.setSubPath(sourceDirectoryName + NfsFile.separator + testFileName); FilesystemConfig targetConfig = new FilesystemConfig(); targetConfig.setPath(filesystemTargetFile.getAbsolutePath()); SyncConfig syncConfig = new SyncConfig().withSource(sourceConfig).withTarget(targetConfig); EcsSync sync = new EcsSync(); sync.setSyncConfig(syncConfig); sync.run(); byte[] sourceBytes = readBytes(sourceFile); byte[] targetBytes = Files.readAllBytes(filesystemTargetFile.toPath()); Assert.assertArrayEquals(sourceBytes, targetBytes); }
@Test public void testSingleFileFromFilesystem() throws Exception { FilesystemConfig sourceConfig = new FilesystemConfig(); sourceConfig.setPath(filesystemSourceFile.getAbsolutePath()); NfsConfig targetConfig = getNfsConfig(nfs); targetConfig.setSubPath(targetDirectoryName + NfsFile.separator + testFileName); SyncConfig syncConfig = new SyncConfig().withSource(sourceConfig).withTarget(targetConfig); EcsSync sync = new EcsSync(); sync.setSyncConfig(syncConfig); sync.run(); byte[] sourceBytes = Files.readAllBytes(filesystemSourceFile.toPath()); byte[] targetBytes = readBytes(targetFile); Assert.assertArrayEquals(sourceBytes, targetBytes); }
fsConfig.setPath(tempDir.getPath());
mimeMap.put("aaa", "application/octet-stream"); FilesystemConfig object = new FilesystemConfig(); object.setPath("/foo/bar"); object.setUseAbsolutePath(true); object.setFollowLinks(true);
fsConfig.setPath(sourceDir.getPath());
tmpConfig.setPath(tempDir.getPath()); tmpConfig.setStoreMetadata(true);