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

The following examples show how to use org.apache.flink.streaming.api.functions.sink.filesystem.bucketassigners.SimpleVersionedStringSerializer. 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: BucketStateSerializerTest.java    From Flink-CEPplus with 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 File: BucketStateSerializerTest.java    From flink with 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 File: BucketStateSerializerTest.java    From flink with 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 #4
Source File: BucketStateSerializerTest.java    From Flink-CEPplus with 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 #5
Source File: CompressWriterFactoryTest.java    From flink with 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 File: BucketStateSerializerTest.java    From flink with 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 #7
Source File: BucketsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #8
Source File: StreamingFileSinkProgram.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #9
Source File: TestUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #10
Source File: TestUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #11
Source File: StreamSQLTestProgram.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #12
Source File: StreamingFileSinkProgram.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #13
Source File: FileSystemTableSink.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #14
Source File: BucketsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #15
Source File: TestUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #16
Source File: TestUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #17
Source File: StreamSQLTestProgram.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #18
Source File: StreamingFileSinkProgram.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #19
Source File: BucketsTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #20
Source File: TestUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #21
Source File: TestUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}
 
Example #22
Source File: StreamSQLTestProgram.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public SimpleVersionedSerializer<String> getSerializer() {
	return SimpleVersionedStringSerializer.INSTANCE;
}