Java Code Examples for org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer

The following examples show how to use org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer. 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: BucketStateSerializerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationEmpty() throws IOException {
	final File testFolder = tempFolder.newFolder();
	final FileSystem fs = FileSystem.get(testFolder.toURI());
	final RecoverableWriter writer = fs.createRecoverableWriter();

	final Path testBucket = new Path(testFolder.getPath(), "test");

	final BucketState<String> bucketState = new BucketState<>(
			"test", testBucket, Long.MAX_VALUE, null, new HashMap<>());

	final SimpleVersionedSerializer<BucketState<String>> serializer =
			new BucketStateSerializer<>(
					writer.getResumeRecoverableSerializer(),
					writer.getCommitRecoverableSerializer(),
					SimpleVersionedStringSerializer.INSTANCE
			);

	byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(serializer, bucketState);
	final BucketState<String> recoveredState =  SimpleVersionedSerialization.readVersionAndDeSerialize(serializer, bytes);

	Assert.assertEquals(testBucket, recoveredState.getBucketPath());
	Assert.assertNull(recoveredState.getInProgressResumableFile());
	Assert.assertTrue(recoveredState.getCommittableFilesPerCheckpoint().isEmpty());
}
 
Example 2
Source Project: flink   Source File: BucketStateSerializerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializationEmpty() throws IOException {
	final File testFolder = tempFolder.newFolder();
	final FileSystem fs = FileSystem.get(testFolder.toURI());
	final RecoverableWriter writer = fs.createRecoverableWriter();

	final Path testBucket = new Path(testFolder.getPath(), "test");

	final BucketState<String> bucketState = new BucketState<>(
			"test", testBucket, Long.MAX_VALUE, null, new HashMap<>());

	final SimpleVersionedSerializer<BucketState<String>> serializer =
			new BucketStateSerializer<>(
					writer.getResumeRecoverableSerializer(),
					writer.getCommitRecoverableSerializer(),
					SimpleVersionedStringSerializer.INSTANCE
			);

	byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(serializer, bucketState);
	final BucketState<String> recoveredState =  SimpleVersionedSerialization.readVersionAndDeSerialize(serializer, bytes);

	Assert.assertEquals(testBucket, recoveredState.getBucketPath());
	Assert.assertNull(recoveredState.getInProgressResumableFile());
	Assert.assertTrue(recoveredState.getCommittableFilesPerCheckpoint().isEmpty());
}
 
Example 3
Source Project: Flink-CEPplus   Source File: BucketStateSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationOnlyInProgress() throws IOException {
	final File testFolder = tempFolder.newFolder();
	final FileSystem fs = FileSystem.get(testFolder.toURI());

	final Path testBucket = new Path(testFolder.getPath(), "test");

	final RecoverableWriter writer = fs.createRecoverableWriter();
	final RecoverableFsDataOutputStream stream = writer.open(testBucket);
	stream.write(IN_PROGRESS_CONTENT.getBytes(Charset.forName("UTF-8")));

	final RecoverableWriter.ResumeRecoverable current = stream.persist();

	final BucketState<String> bucketState = new BucketState<>(
			"test", testBucket, Long.MAX_VALUE, current, new HashMap<>());

	final SimpleVersionedSerializer<BucketState<String>> serializer =
			new BucketStateSerializer<>(
					writer.getResumeRecoverableSerializer(),
					writer.getCommitRecoverableSerializer(),
					SimpleVersionedStringSerializer.INSTANCE
			);

	final byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(serializer, bucketState);

	// to simulate that everything is over for file.
	stream.close();

	final BucketState<String> recoveredState =  SimpleVersionedSerialization.readVersionAndDeSerialize(serializer, bytes);

	Assert.assertEquals(testBucket, recoveredState.getBucketPath());

	FileStatus[] statuses = fs.listStatus(testBucket.getParent());
	Assert.assertEquals(1L, statuses.length);
	Assert.assertTrue(
			statuses[0].getPath().getPath().startsWith(
					(new Path(testBucket.getParent(), ".test.inprogress")).toString())
	);
}
 
Example 4
Source Project: flink   Source File: BucketStateSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSerializationOnlyInProgress() throws IOException {
	final File testFolder = tempFolder.newFolder();
	final FileSystem fs = FileSystem.get(testFolder.toURI());

	final Path testBucket = new Path(testFolder.getPath(), "test");

	final RecoverableWriter writer = fs.createRecoverableWriter();
	final RecoverableFsDataOutputStream stream = writer.open(testBucket);
	stream.write(IN_PROGRESS_CONTENT.getBytes(Charset.forName("UTF-8")));

	final RecoverableWriter.ResumeRecoverable current = stream.persist();

	final BucketState<String> bucketState = new BucketState<>(
			"test", testBucket, Long.MAX_VALUE, current, new HashMap<>());

	final SimpleVersionedSerializer<BucketState<String>> serializer =
			new BucketStateSerializer<>(
					writer.getResumeRecoverableSerializer(),
					writer.getCommitRecoverableSerializer(),
					SimpleVersionedStringSerializer.INSTANCE
			);

	final byte[] bytes = SimpleVersionedSerialization.writeVersionAndSerialize(serializer, bucketState);

	// to simulate that everything is over for file.
	stream.close();

	final BucketState<String> recoveredState =  SimpleVersionedSerialization.readVersionAndDeSerialize(serializer, bytes);

	Assert.assertEquals(testBucket, recoveredState.getBucketPath());

	FileStatus[] statuses = fs.listStatus(testBucket.getParent());
	Assert.assertEquals(1L, statuses.length);
	Assert.assertTrue(
			statuses[0].getPath().getPath().startsWith(
					(new Path(testBucket.getParent(), ".test.inprogress")).getPath())
	);
}
 
Example 5
Source Project: flink   Source File: CompressWriterFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
private File prepareCompressedFile(CompressWriterFactory<String> writer, List<String> lines) throws Exception {
	final File outDir = TEMPORARY_FOLDER.newFolder();

	final BucketAssigner<String, String> assigner = new BucketAssigner<String, String> () {
		@Override
		public String getBucketId(String element, BucketAssigner.Context context) {
			return "bucket";
		}

		@Override
		public SimpleVersionedSerializer<String> getSerializer() {
			return SimpleVersionedStringSerializer.INSTANCE;
		}
	};

	StreamingFileSink<String> sink = StreamingFileSink
		.forBulkFormat(new Path(outDir.toURI()), writer)
		.withBucketAssigner(assigner)
		.build();

	try (
		OneInputStreamOperatorTestHarness<String, Object> testHarness = new OneInputStreamOperatorTestHarness<>(new StreamSink<>(sink), 1, 1, 0)
	) {
		testHarness.setup();
		testHarness.open();

		int time = 0;
		for (String line: lines) {
			testHarness.processElement(new StreamRecord<>(line, ++time));
		}

		testHarness.snapshot(1, ++time);
		testHarness.notifyOfCompletedCheckpoint(1);
	}

	return outDir;
}
 
Example 6
Source Project: flink   Source File: BucketStateSerializerTest.java    License: Apache License 2.0 5 votes vote down vote up
private static SimpleVersionedSerializer<BucketState<String>> bucketStateSerializer() throws IOException {
	final RowWiseBucketWriter bucketWriter = createBucketWriter();
	return new BucketStateSerializer<>(
		bucketWriter.getProperties().getInProgressFileRecoverableSerializer(),
		bucketWriter.getProperties().getPendingFileRecoverableSerializer(),
		SimpleVersionedStringSerializer.INSTANCE);
}
 
Example 7
Source Project: Flink-CEPplus   Source File: StreamingFileSinkProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 8
Source Project: Flink-CEPplus   Source File: StreamSQLTestProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 9
Source Project: Flink-CEPplus   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 10
Source Project: Flink-CEPplus   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 11
Source Project: Flink-CEPplus   Source File: BucketsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 12
Source Project: flink   Source File: StreamingFileSinkProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 13
Source Project: flink   Source File: StreamSQLTestProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 14
Source Project: flink   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 15
Source Project: flink   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 16
Source Project: flink   Source File: BucketsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 17
Source Project: flink   Source File: FileSystemTableSink.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 18
Source Project: flink   Source File: StreamingFileSinkProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 19
Source Project: flink   Source File: StreamSQLTestProgram.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 20
Source Project: flink   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 21
Source Project: flink   Source File: TestUtils.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example 22
Source Project: flink   Source File: BucketsTest.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}