Java Code Examples for org.apache.flink.core.fs.local.LocalFileSystem

The following examples show how to use org.apache.flink.core.fs.local.LocalFileSystem. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Flink-CEPplus   Source File: FileSystemTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() throws URISyntaxException, IOException {
	String scheme = "file";

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":///test/test") instanceof LocalFileSystem);

	try {
		getFileSystemWithoutSafetyNet(scheme + "://test/test");
	} catch (IOException ioe) {
		assertTrue(ioe.getMessage().startsWith("Found local file path with authority '"));
	}

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("test/test") instanceof LocalFileSystem);
}
 
Example 2
@Test
public void testConstructionNumericOverflow() {
	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			Integer.MAX_VALUE,  // unlimited total
			Integer.MAX_VALUE,  // limited outgoing
			Integer.MAX_VALUE,  // unlimited incoming
			Long.MAX_VALUE - 1, // long timeout, close to overflow
			Long.MAX_VALUE - 1); // long timeout, close to overflow

	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenStreamsTotal());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenOutputStreams());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenInputStreams());

	assertTrue(limitedFs.getStreamOpenTimeout() > 0);
	assertTrue(limitedFs.getStreamInactivityTimeout() > 0);
}
 
Example 3
Source Project: Flink-CEPplus   Source File: PendingCheckpointTest.java    License: Apache License 2.0 6 votes vote down vote up
private PendingCheckpoint createPendingCheckpoint(CheckpointProperties props, Executor executor) throws IOException {

		final Path checkpointDir = new Path(tmpFolder.newFolder().toURI());
		final FsCheckpointStorageLocation location = new FsCheckpointStorageLocation(
				LocalFileSystem.getSharedInstance(),
				checkpointDir, checkpointDir, checkpointDir,
				CheckpointStorageLocationReference.getDefault(),
				1024);

		final Map<ExecutionAttemptID, ExecutionVertex> ackTasks = new HashMap<>(ACK_TASKS);

		return new PendingCheckpoint(
			new JobID(),
			0,
			1,
			ackTasks,
			props,
			location,
			executor);
	}
 
Example 4
Source Project: Flink-CEPplus   Source File: FsCheckpointStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveCheckpointStorageLocation() throws Exception {
	final FileSystem checkpointFileSystem = mock(FileSystem.class);
	final FsCheckpointStorage storage = new FsCheckpointStorage(
		new TestingPath("hdfs:///checkpoint/", checkpointFileSystem),
		null,
		new JobID(),
		FILE_SIZE_THRESHOLD);

	final FsCheckpointStorageLocation checkpointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(1L, CheckpointStorageLocationReference.getDefault());
	assertEquals(checkpointFileSystem, checkpointStreamFactory.getFileSystem());

	final CheckpointStorageLocationReference savepointLocationReference =
		AbstractFsCheckpointStorage.encodePathAsReference(new Path("file:///savepoint/"));

	final FsCheckpointStorageLocation savepointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(2L, savepointLocationReference);
	final FileSystem fileSystem = savepointStreamFactory.getFileSystem();
	assertTrue(fileSystem instanceof LocalFileSystem);
}
 
Example 5
Source Project: flink   Source File: FileSystemTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() throws URISyntaxException, IOException {
	String scheme = "file";

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":///test/test") instanceof LocalFileSystem);

	try {
		getFileSystemWithoutSafetyNet(scheme + "://test/test");
	} catch (IOException ioe) {
		assertTrue(ioe.getMessage().startsWith("Found local file path with authority '"));
	}

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("test/test") instanceof LocalFileSystem);
}
 
Example 6
Source Project: flink   Source File: LimitedConnectionsFileSystemTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructionNumericOverflow() {
	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			Integer.MAX_VALUE,  // unlimited total
			Integer.MAX_VALUE,  // limited outgoing
			Integer.MAX_VALUE,  // unlimited incoming
			Long.MAX_VALUE - 1, // long timeout, close to overflow
			Long.MAX_VALUE - 1); // long timeout, close to overflow

	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenStreamsTotal());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenOutputStreams());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenInputStreams());

	assertTrue(limitedFs.getStreamOpenTimeout() > 0);
	assertTrue(limitedFs.getStreamInactivityTimeout() > 0);
}
 
Example 7
Source Project: flink   Source File: PendingCheckpointTest.java    License: Apache License 2.0 6 votes vote down vote up
private PendingCheckpoint createPendingCheckpoint(CheckpointProperties props, Executor executor) throws IOException {

		final Path checkpointDir = new Path(tmpFolder.newFolder().toURI());
		final FsCheckpointStorageLocation location = new FsCheckpointStorageLocation(
				LocalFileSystem.getSharedInstance(),
				checkpointDir, checkpointDir, checkpointDir,
				CheckpointStorageLocationReference.getDefault(),
				1024,
				4096);

		final Map<ExecutionAttemptID, ExecutionVertex> ackTasks = new HashMap<>(ACK_TASKS);

		return new PendingCheckpoint(
			new JobID(),
			0,
			1,
			ackTasks,
			props,
			location,
			executor);
	}
 
Example 8
Source Project: flink   Source File: FsCheckpointStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveCheckpointStorageLocation() throws Exception {
	final FileSystem checkpointFileSystem = mock(FileSystem.class);
	final FsCheckpointStorage storage = new FsCheckpointStorage(
		new TestingPath("hdfs:///checkpoint/", checkpointFileSystem),
		null,
		new JobID(),
		FILE_SIZE_THRESHOLD,
		WRITE_BUFFER_SIZE);

	final FsCheckpointStorageLocation checkpointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(1L, CheckpointStorageLocationReference.getDefault());
	assertEquals(checkpointFileSystem, checkpointStreamFactory.getFileSystem());

	final CheckpointStorageLocationReference savepointLocationReference =
		AbstractFsCheckpointStorage.encodePathAsReference(new Path("file:///savepoint/"));

	final FsCheckpointStorageLocation savepointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(2L, savepointLocationReference);
	final FileSystem fileSystem = savepointStreamFactory.getFileSystem();
	assertTrue(fileSystem instanceof LocalFileSystem);
}
 
Example 9
Source Project: flink   Source File: FileSystemTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() throws URISyntaxException, IOException {
	String scheme = "file";

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":///test/test") instanceof LocalFileSystem);

	try {
		getFileSystemWithoutSafetyNet(scheme + "://test/test");
	} catch (IOException ioe) {
		assertTrue(ioe.getMessage().startsWith("Found local file path with authority '"));
	}

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet(scheme + ":test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("/test/test") instanceof LocalFileSystem);

	assertTrue(getFileSystemWithoutSafetyNet("test/test") instanceof LocalFileSystem);
}
 
Example 10
Source Project: flink   Source File: LimitedConnectionsFileSystemTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructionNumericOverflow() {
	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			Integer.MAX_VALUE,  // unlimited total
			Integer.MAX_VALUE,  // limited outgoing
			Integer.MAX_VALUE,  // unlimited incoming
			Long.MAX_VALUE - 1, // long timeout, close to overflow
			Long.MAX_VALUE - 1); // long timeout, close to overflow

	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenStreamsTotal());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenOutputStreams());
	assertEquals(Integer.MAX_VALUE, limitedFs.getMaxNumOpenInputStreams());

	assertTrue(limitedFs.getStreamOpenTimeout() > 0);
	assertTrue(limitedFs.getStreamInactivityTimeout() > 0);
}
 
Example 11
Source Project: flink   Source File: FsCheckpointStorageTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveCheckpointStorageLocation() throws Exception {
	final FileSystem checkpointFileSystem = mock(FileSystem.class);
	final FsCheckpointStorage storage = new FsCheckpointStorage(
		new TestingPath("hdfs:///checkpoint/", checkpointFileSystem),
		null,
		new JobID(),
		FILE_SIZE_THRESHOLD,
		WRITE_BUFFER_SIZE);

	final FsCheckpointStorageLocation checkpointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(1L, CheckpointStorageLocationReference.getDefault());
	assertEquals(checkpointFileSystem, checkpointStreamFactory.getFileSystem());

	final CheckpointStorageLocationReference savepointLocationReference =
		AbstractFsCheckpointStorage.encodePathAsReference(new Path("file:///savepoint/"));

	final FsCheckpointStorageLocation savepointStreamFactory =
		(FsCheckpointStorageLocation) storage.resolveCheckpointStorageLocation(2L, savepointLocationReference);
	final FileSystem fileSystem = savepointStreamFactory.getFileSystem();
	assertTrue(fileSystem instanceof LocalFileSystem);
}
 
Example 12
Source Project: Flink-CEPplus   Source File: CollectionExecutor.java    License: Apache License 2.0 5 votes vote down vote up
public CompletedFuture(Path entry) {
	try{
		LocalFileSystem fs = (LocalFileSystem) FileSystem.getUnguardedFileSystem(entry.toUri());
		result = entry.isAbsolute() ? new Path(entry.toUri().getPath()): new Path(fs.getWorkingDirectory(),entry);
	} catch (Exception e){
		throw new RuntimeException("DistributedCache supports only local files for Collection Environments");
	}
}
 
Example 13
Source Project: Flink-CEPplus   Source File: FilesystemSchemeConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitlySetToLocal() throws Exception {
	final Configuration conf = new Configuration();
	conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString());
	FileSystem.initialize(conf);

	URI justPath = new URI(tempFolder.newFile().toURI().getPath());
	assertNull(justPath.getScheme());

	FileSystem fs = FileSystem.get(justPath);
	assertEquals("file", fs.getUri().getScheme());
}
 
Example 14
@Test
public void testOpenTimeoutOutputStreams() throws Exception {
	final long openTimeout = 50L;
	final int maxConcurrentOpen = 2;

	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			maxConcurrentOpen, // limited total
			openTimeout,       // small opening timeout
			0L);               // infinite inactivity timeout

	// create the threads that block all streams
	final BlockingWriterThread[] threads = new BlockingWriterThread[maxConcurrentOpen];
	for (int i = 0; i < maxConcurrentOpen; i++) {
		Path path = new Path(tempFolder.newFile().toURI());
		threads[i] = new BlockingWriterThread(limitedFs, path, Integer.MAX_VALUE, maxConcurrentOpen);
		threads[i].start();
	}

	// wait until all are open
	while (limitedFs.getTotalNumberOfOpenStreams() < maxConcurrentOpen) {
		Thread.sleep(1);
	}

	// try to open another thread
	try {
		limitedFs.create(new Path(tempFolder.newFile().toURI()), WriteMode.OVERWRITE);
		fail("this should have timed out");
	}
	catch (IOException e) {
		// expected
	}

	// clean shutdown
	for (BlockingWriterThread t : threads) {
		t.wakeup();
		t.sync();
	}
}
 
Example 15
Source Project: Flink-CEPplus   Source File: EntropyInjectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEntropyAwarePlainFs() throws Exception {
	File folder = TMP_FOLDER.newFolder();
	Path path = new Path(Path.fromLocalFile(folder), "_entropy_/file");

	OutputStreamAndPath out = EntropyInjector.createEntropyAware(
			LocalFileSystem.getSharedInstance(), path, WriteMode.NO_OVERWRITE);

	out.stream().close();

	assertEquals(path, out.path());
	assertTrue(new File (new File(folder, "_entropy_"), "file").exists());
}
 
Example 16
Source Project: Flink-CEPplus   Source File: BucketTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TestRecoverableWriter getRecoverableWriter(Path path) {
	try {
		final FileSystem fs = FileSystem.get(path.toUri());
		if (!(fs instanceof LocalFileSystem)) {
			fail("Expected Local FS but got a " + fs.getClass().getName() + " for path: " + path);
		}
		return new TestRecoverableWriter((LocalFileSystem) fs);
	} catch (IOException e) {
		fail();
	}
	return null;
}
 
Example 17
Source Project: flink   Source File: CollectionExecutor.java    License: Apache License 2.0 5 votes vote down vote up
public CompletedFuture(Path entry) {
	try{
		LocalFileSystem fs = (LocalFileSystem) FileSystem.getUnguardedFileSystem(entry.toUri());
		result = entry.isAbsolute() ? new Path(entry.toUri().getPath()): new Path(fs.getWorkingDirectory(),entry);
	} catch (Exception e){
		throw new RuntimeException("DistributedCache supports only local files for Collection Environments");
	}
}
 
Example 18
Source Project: flink   Source File: FilesystemSchemeConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitlySetToLocal() throws Exception {
	final Configuration conf = new Configuration();
	conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString());
	FileSystem.initialize(conf);

	URI justPath = new URI(tempFolder.newFile().toURI().getPath());
	assertNull(justPath.getScheme());

	FileSystem fs = FileSystem.get(justPath);
	assertEquals("file", fs.getUri().getScheme());
}
 
Example 19
Source Project: flink   Source File: LimitedConnectionsFileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOpenTimeoutOutputStreams() throws Exception {
	final long openTimeout = 50L;
	final int maxConcurrentOpen = 2;

	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			maxConcurrentOpen, // limited total
			openTimeout,       // small opening timeout
			0L);               // infinite inactivity timeout

	// create the threads that block all streams
	final BlockingWriterThread[] threads = new BlockingWriterThread[maxConcurrentOpen];
	for (int i = 0; i < maxConcurrentOpen; i++) {
		Path path = new Path(tempFolder.newFile().toURI());
		threads[i] = new BlockingWriterThread(limitedFs, path, Integer.MAX_VALUE, maxConcurrentOpen);
		threads[i].start();
	}

	// wait until all are open
	while (limitedFs.getTotalNumberOfOpenStreams() < maxConcurrentOpen) {
		Thread.sleep(1);
	}

	// try to open another thread
	try {
		limitedFs.create(new Path(tempFolder.newFile().toURI()), WriteMode.OVERWRITE);
		fail("this should have timed out");
	}
	catch (IOException e) {
		// expected
	}

	// clean shutdown
	for (BlockingWriterThread t : threads) {
		t.wakeup();
		t.sync();
	}
}
 
Example 20
Source Project: flink   Source File: EntropyInjectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEntropyAwarePlainFs() throws Exception {
	File folder = TMP_FOLDER.newFolder();
	Path path = new Path(Path.fromLocalFile(folder), "_entropy_/file");

	OutputStreamAndPath out = EntropyInjector.createEntropyAware(
			LocalFileSystem.getSharedInstance(), path, WriteMode.NO_OVERWRITE);

	out.stream().close();

	assertEquals(path, out.path());
	assertTrue(new File (new File(folder, "_entropy_"), "file").exists());
}
 
Example 21
Source Project: flink   Source File: BucketTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TestRecoverableWriter getRecoverableWriter(Path path) {
	try {
		final FileSystem fs = FileSystem.get(path.toUri());
		if (!(fs instanceof LocalFileSystem)) {
			fail("Expected Local FS but got a " + fs.getClass().getName() + " for path: " + path);
		}
		return new TestRecoverableWriter((LocalFileSystem) fs);
	} catch (IOException e) {
		fail();
	}
	return null;
}
 
Example 22
Source Project: flink   Source File: CollectionExecutor.java    License: Apache License 2.0 5 votes vote down vote up
public CompletedFuture(Path entry) {
	try{
		LocalFileSystem fs = (LocalFileSystem) FileSystem.getUnguardedFileSystem(entry.toUri());
		result = entry.isAbsolute() ? new Path(entry.toUri().getPath()): new Path(fs.getWorkingDirectory(),entry);
	} catch (Exception e){
		throw new RuntimeException("DistributedCache supports only local files for Collection Environments");
	}
}
 
Example 23
Source Project: flink   Source File: FilesystemSchemeConfigTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testExplicitlySetToLocal() throws Exception {
	final Configuration conf = new Configuration();
	conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString());
	FileSystem.initialize(conf);

	URI justPath = new URI(tempFolder.newFile().toURI().getPath());
	assertNull(justPath.getScheme());

	FileSystem fs = FileSystem.get(justPath);
	assertEquals("file", fs.getUri().getScheme());
}
 
Example 24
Source Project: flink   Source File: LimitedConnectionsFileSystemTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testOpenTimeoutOutputStreams() throws Exception {
	final long openTimeout = 50L;
	final int maxConcurrentOpen = 2;

	final LimitedConnectionsFileSystem limitedFs = new LimitedConnectionsFileSystem(
			LocalFileSystem.getSharedInstance(),
			maxConcurrentOpen, // limited total
			openTimeout,       // small opening timeout
			0L);               // infinite inactivity timeout

	// create the threads that block all streams
	final BlockingWriterThread[] threads = new BlockingWriterThread[maxConcurrentOpen];
	for (int i = 0; i < maxConcurrentOpen; i++) {
		Path path = new Path(tempFolder.newFile().toURI());
		threads[i] = new BlockingWriterThread(limitedFs, path, Integer.MAX_VALUE, maxConcurrentOpen);
		threads[i].start();
	}

	// wait until all are open
	while (limitedFs.getTotalNumberOfOpenStreams() < maxConcurrentOpen) {
		Thread.sleep(1);
	}

	// try to open another thread
	try {
		limitedFs.create(new Path(tempFolder.newFile().toURI()), WriteMode.OVERWRITE);
		fail("this should have timed out");
	}
	catch (IOException e) {
		// expected
	}

	// clean shutdown
	for (BlockingWriterThread t : threads) {
		t.wakeup();
		t.sync();
	}
}
 
Example 25
Source Project: flink   Source File: EntropyInjectorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEntropyAwarePlainFs() throws Exception {
	File folder = TMP_FOLDER.newFolder();
	Path path = new Path(Path.fromLocalFile(folder), "_entropy_/file");

	OutputStreamAndPath out = EntropyInjector.createEntropyAware(
			LocalFileSystem.getSharedInstance(), path, WriteMode.NO_OVERWRITE);

	out.stream().close();

	assertEquals(path, out.path());
	assertTrue(new File (new File(folder, "_entropy_"), "file").exists());
}
 
Example 26
Source Project: flink   Source File: PendingCheckpointTest.java    License: Apache License 2.0 5 votes vote down vote up
private PendingCheckpoint createPendingCheckpoint(
		CheckpointProperties props,
		Collection<OperatorID> operatorCoordinators,
		Collection<String> masterStateIdentifiers,
		Executor executor) throws IOException {

	final Path checkpointDir = new Path(tmpFolder.newFolder().toURI());
	final FsCheckpointStorageLocation location = new FsCheckpointStorageLocation(
			LocalFileSystem.getSharedInstance(),
			checkpointDir, checkpointDir, checkpointDir,
			CheckpointStorageLocationReference.getDefault(),
			1024,
			4096);

	final Map<ExecutionAttemptID, ExecutionVertex> ackTasks = new HashMap<>(ACK_TASKS);

	return new PendingCheckpoint(
		new JobID(),
		0,
		1,
		ackTasks,
		operatorCoordinators,
		masterStateIdentifiers,
		props,
		location,
		executor,
		new CompletableFuture<>());
}
 
Example 27
Source Project: flink   Source File: BucketTest.java    License: Apache License 2.0 5 votes vote down vote up
private static TestRecoverableWriter getRecoverableWriter(Path path) {
	try {
		final FileSystem fs = FileSystem.get(path.toUri());
		if (!(fs instanceof LocalFileSystem)) {
			fail("Expected Local FS but got a " + fs.getClass().getName() + " for path: " + path);
		}
		return new TestRecoverableWriter((LocalFileSystem) fs);
	} catch (IOException e) {
		fail();
	}
	return null;
}
 
Example 28
Source Project: Flink-CEPplus   Source File: InitOutputPathTest.java    License: Apache License 2.0 4 votes vote down vote up
private void runTest(final boolean useAwaits) throws Exception {
	final File tempFile = tempDir.newFile();
	final Path path1 = new Path(tempFile.getAbsolutePath(), "1");
	final Path path2 = new Path(tempFile.getAbsolutePath(), "2");

	final OneShotLatch deleteAwaitLatch1 = new OneShotLatch();
	final OneShotLatch deleteAwaitLatch2 = new OneShotLatch();
	final OneShotLatch mkdirsAwaitLatch1 = new OneShotLatch();
	final OneShotLatch mkdirsAwaitLatch2 = new OneShotLatch();

	final OneShotLatch deleteTriggerLatch1 = new OneShotLatch();
	final OneShotLatch deletetriggerLatch2 = new OneShotLatch();
	final OneShotLatch mkdirsTriggerLatch1 = new OneShotLatch();
	final OneShotLatch mkdirsTriggerLatch2 = new OneShotLatch();

	final OneShotLatch createAwaitLatch = new OneShotLatch();
	final OneShotLatch createTriggerLatch = new OneShotLatch();

	// this "new LocalDataOutputStream()" is in the end called by the async threads
	whenNew(LocalDataOutputStream.class).withAnyArguments().thenAnswer(new Answer<LocalDataOutputStream>() {

		@Override
		public LocalDataOutputStream answer(InvocationOnMock invocation) throws Throwable {
			createAwaitLatch.trigger();
			createTriggerLatch.await();

			final File file = (File) invocation.getArguments()[0];
			return new LocalDataOutputStream(file);
		}
	});

	final LocalFileSystem fs1 = new SyncedFileSystem(
			deleteAwaitLatch1, mkdirsAwaitLatch1,
			deleteTriggerLatch1, mkdirsTriggerLatch1);

	final LocalFileSystem fs2 = new SyncedFileSystem(
			deleteAwaitLatch2, mkdirsAwaitLatch2,
			deletetriggerLatch2, mkdirsTriggerLatch2);

	// start the concurrent file creators
	FileCreator thread1 = new FileCreator(fs1, path1);
	FileCreator thread2 = new FileCreator(fs2, path2);
	thread1.start();
	thread2.start();

	// wait until they both decide to delete the directory
	if (useAwaits) {
		deleteAwaitLatch1.await();
		deleteAwaitLatch2.await();
	} else {
		Thread.sleep(5);
	}

	// now send off #1 to delete the directory (it will pass the 'mkdirs' fast) and wait to create the file
	mkdirsTriggerLatch1.trigger();
	deleteTriggerLatch1.trigger();

	if (useAwaits) {
		createAwaitLatch.await();
	} else {
		// this needs a bit more sleep time, because here mockito is working
		Thread.sleep(100);
	}

	// now send off #2 to delete the directory - it waits at 'mkdirs'
	deletetriggerLatch2.trigger();
	if (useAwaits) {
		mkdirsAwaitLatch2.await();
	} else {
		Thread.sleep(5);
	}

	// let #1 try to create the file and see if it succeeded
	createTriggerLatch.trigger();
	if (useAwaits) {
		thread1.sync();
	} else {
		Thread.sleep(5);
	}

	// now let #1 finish up
	mkdirsTriggerLatch2.trigger();

	thread1.sync();
	thread2.sync();
}
 
Example 29
Source Project: Flink-CEPplus   Source File: PythonStreamBinderTest.java    License: Apache License 2.0 4 votes vote down vote up
private static Path getBaseTestPythonDir() {
	FileSystem fs = new LocalFileSystem();
	return new Path(fs.getWorkingDirectory(), "src/test/python/org/apache/flink/streaming/python/api");
}
 
Example 30
@Override
public FileSystem getFileSystem() throws Exception {
	org.apache.hadoop.fs.FileSystem fs = new RawLocalFileSystem();
	fs.initialize(LocalFileSystem.getLocalFsURI(), new Configuration());
	return new HadoopFileSystem(fs);
}