org.apache.flink.testutils.TestFileSystem Java Examples

The following examples show how to use org.apache.flink.testutils.TestFileSystem. 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 File: DelimitedInputFormatSamplingTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesOneFile() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #2
Source File: DelimitedInputFormatSamplingTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesMultipleFiles() {
	try {
		final String tempFile = TestFileUtils.createTempFileDir(testTempFolder, TEST_DATA1, TEST_DATA1, TEST_DATA1, TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #3
Source File: DelimitedInputFormatSamplingTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachedStatistics() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath("test://" + tempFile);
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats = format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		final TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath("test://" + tempFile);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats2 = format2.getStatistics(stats);
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", 0 == TestFileSystem.getNumtimeStreamOpened());
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", stats == stats2);
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #4
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesOneFile() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #5
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesMultipleFiles() {
	try {
		final String tempFile = TestFileUtils.createTempFileDir(testTempFolder, TEST_DATA1, TEST_DATA1, TEST_DATA1, TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #6
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachedStatistics() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath("test://" + tempFile);
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats = format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		final TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath("test://" + tempFile);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats2 = format2.getStatistics(stats);
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", 0 == TestFileSystem.getNumtimeStreamOpened());
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", stats == stats2);
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #7
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesOneFile() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #8
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumSamplesMultipleFiles() {
	try {
		final String tempFile = TestFileUtils.createTempFileDir(testTempFolder, TEST_DATA1, TEST_DATA1, TEST_DATA1, TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath(tempFile.replace("file", "test"));
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath(tempFile.replace("file", "test"));
		format2.setNumLineSamples(8);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		format2.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", 8, TestFileSystem.getNumtimeStreamOpened());
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #9
Source File: DelimitedInputFormatSamplingTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachedStatistics() {
	try {
		final String tempFile = TestFileUtils.createTempFile(TEST_DATA1);
		final Configuration conf = new Configuration();
		
		final TestDelimitedInputFormat format = new TestDelimitedInputFormat(CONFIG);
		format.setFilePath("test://" + tempFile);
		format.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats = format.getStatistics(null);
		Assert.assertEquals("Wrong number of samples taken.", DEFAULT_NUM_SAMPLES, TestFileSystem.getNumtimeStreamOpened());
		
		final TestDelimitedInputFormat format2 = new TestDelimitedInputFormat(CONFIG);
		format2.setFilePath("test://" + tempFile);
		format2.configure(conf);
		
		TestFileSystem.resetStreamOpenCounter();
		BaseStatistics stats2 = format2.getStatistics(stats);
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", 0 == TestFileSystem.getNumtimeStreamOpened());
		Assert.assertTrue("Using cached statistics should cicumvent sampling.", stats == stats2);
		
	} catch (Exception e) {
		e.printStackTrace();
		Assert.fail(e.getMessage());
	}
}
 
Example #10
Source File: LimitedConnectionsConfigurationTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * This test validates that the File System is correctly wrapped by the
 * file system factories when the corresponding entries are in the configuration.
 */
@Test
public void testConfiguration() throws Exception {
	final String fsScheme = TestFileSystem.SCHEME;

	// nothing configured, we should get a regular file system
	FileSystem schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
	FileSystem localFs = FileSystem.get(tempDir.newFile().toURI());

	assertFalse(schemeFs instanceof LimitedConnectionsFileSystem);
	assertFalse(localFs instanceof LimitedConnectionsFileSystem);

	// configure some limits, which should cause "fsScheme" to be limited

	final Configuration config = new Configuration();
	config.setInteger("fs." + fsScheme + ".limit.total", 42);
	config.setInteger("fs." + fsScheme + ".limit.input", 11);
	config.setInteger("fs." + fsScheme + ".limit.output", 40);
	config.setInteger("fs." + fsScheme + ".limit.timeout", 12345);
	config.setInteger("fs." + fsScheme + ".limit.stream-timeout", 98765);

	try {
		FileSystem.initialize(config);

		schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
		localFs = FileSystem.get(tempDir.newFile().toURI());

		assertTrue(schemeFs instanceof LimitedConnectionsFileSystem);
		assertFalse(localFs instanceof LimitedConnectionsFileSystem);

		LimitedConnectionsFileSystem limitedFs = (LimitedConnectionsFileSystem) schemeFs;
		assertEquals(42, limitedFs.getMaxNumOpenStreamsTotal());
		assertEquals(11, limitedFs.getMaxNumOpenInputStreams());
		assertEquals(40, limitedFs.getMaxNumOpenOutputStreams());
		assertEquals(12345, limitedFs.getStreamOpenTimeout());
		assertEquals(98765, limitedFs.getStreamInactivityTimeout());
	}
	finally {
		// clear all settings
		FileSystem.initialize(new Configuration());
	}
}
 
Example #11
Source File: LimitedConnectionsConfigurationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This test validates that the File System is correctly wrapped by the
 * file system factories when the corresponding entries are in the configuration.
 */
@Test
public void testConfiguration() throws Exception {
	final String fsScheme = TestFileSystem.SCHEME;

	// nothing configured, we should get a regular file system
	FileSystem schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
	FileSystem localFs = FileSystem.get(tempDir.newFile().toURI());

	assertFalse(schemeFs instanceof LimitedConnectionsFileSystem);
	assertFalse(localFs instanceof LimitedConnectionsFileSystem);

	// configure some limits, which should cause "fsScheme" to be limited

	final Configuration config = new Configuration();
	config.setInteger("fs." + fsScheme + ".limit.total", 42);
	config.setInteger("fs." + fsScheme + ".limit.input", 11);
	config.setInteger("fs." + fsScheme + ".limit.output", 40);
	config.setInteger("fs." + fsScheme + ".limit.timeout", 12345);
	config.setInteger("fs." + fsScheme + ".limit.stream-timeout", 98765);

	try {
		FileSystem.initialize(config);

		schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
		localFs = FileSystem.get(tempDir.newFile().toURI());

		assertTrue(schemeFs instanceof LimitedConnectionsFileSystem);
		assertFalse(localFs instanceof LimitedConnectionsFileSystem);

		LimitedConnectionsFileSystem limitedFs = (LimitedConnectionsFileSystem) schemeFs;
		assertEquals(42, limitedFs.getMaxNumOpenStreamsTotal());
		assertEquals(11, limitedFs.getMaxNumOpenInputStreams());
		assertEquals(40, limitedFs.getMaxNumOpenOutputStreams());
		assertEquals(12345, limitedFs.getStreamOpenTimeout());
		assertEquals(98765, limitedFs.getStreamInactivityTimeout());
	}
	finally {
		// clear all settings
		FileSystem.initialize(new Configuration());
	}
}
 
Example #12
Source File: LimitedConnectionsConfigurationTest.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * This test validates that the File System is correctly wrapped by the
 * file system factories when the corresponding entries are in the configuration.
 */
@Test
public void testConfiguration() throws Exception {
	final String fsScheme = TestFileSystem.SCHEME;

	// nothing configured, we should get a regular file system
	FileSystem schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
	FileSystem localFs = FileSystem.get(tempDir.newFile().toURI());

	assertFalse(schemeFs instanceof LimitedConnectionsFileSystem);
	assertFalse(localFs instanceof LimitedConnectionsFileSystem);

	// configure some limits, which should cause "fsScheme" to be limited

	final Configuration config = new Configuration();
	config.setInteger("fs." + fsScheme + ".limit.total", 42);
	config.setInteger("fs." + fsScheme + ".limit.input", 11);
	config.setInteger("fs." + fsScheme + ".limit.output", 40);
	config.setInteger("fs." + fsScheme + ".limit.timeout", 12345);
	config.setInteger("fs." + fsScheme + ".limit.stream-timeout", 98765);

	try {
		FileSystem.initialize(config);

		schemeFs = FileSystem.get(URI.create(fsScheme + ":///a/b/c"));
		localFs = FileSystem.get(tempDir.newFile().toURI());

		assertTrue(schemeFs instanceof LimitedConnectionsFileSystem);
		assertFalse(localFs instanceof LimitedConnectionsFileSystem);

		LimitedConnectionsFileSystem limitedFs = (LimitedConnectionsFileSystem) schemeFs;
		assertEquals(42, limitedFs.getMaxNumOpenStreamsTotal());
		assertEquals(11, limitedFs.getMaxNumOpenInputStreams());
		assertEquals(40, limitedFs.getMaxNumOpenOutputStreams());
		assertEquals(12345, limitedFs.getStreamOpenTimeout());
		assertEquals(98765, limitedFs.getStreamInactivityTimeout());
	}
	finally {
		// clear all settings
		FileSystem.initialize(new Configuration());
	}
}