Java Code Examples for org.apache.flink.core.fs.RecoverableFsDataOutputStream#persist()
The following examples show how to use
org.apache.flink.core.fs.RecoverableFsDataOutputStream#persist() .
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: HadoopS3RecoverableWriterITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(expected = FileNotFoundException.class) public void testCleanupRecoverableState() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); // this should throw the exception as we deleted the file. getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); }
Example 2
Source File: HadoopS3RecoverableWriterExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeWithWrongOffset() throws Exception { // this is a rather unrealistic scenario, but it is to trigger // truncation of the file and try to resume with missing data. final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable1 = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable2 = stream.persist(); stream.write(testData3.getBytes(StandardCharsets.UTF_8)); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable1); recoveredStream.closeForCommit().commit(); // this should throw an exception final RecoverableFsDataOutputStream newRecoveredStream = writer.recover(recoverable2); newRecoveredStream.closeForCommit().commit(); }
Example 3
Source File: HadoopS3RecoverableWriterExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeAfterCommit() throws Exception { final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); stream.closeForCommit().commit(); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable); recoveredStream.closeForCommit().commit(); }
Example 4
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testCallingDeleteObjectTwiceDoesNotThroughException() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); boolean unsuccessfulDeletion = writer.cleanupRecoverableState(recoverable); Assert.assertFalse(unsuccessfulDeletion); }
Example 5
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = FileNotFoundException.class) public void testCleanupRecoverableState() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); // this should throw the exception as we deleted the file. getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); }
Example 6
Source File: HadoopS3RecoverableWriterExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeWithWrongOffset() throws Exception { // this is a rather unrealistic scenario, but it is to trigger // truncation of the file and try to resume with missing data. final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable1 = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable2 = stream.persist(); stream.write(testData3.getBytes(StandardCharsets.UTF_8)); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable1); recoveredStream.closeForCommit().commit(); // this should throw an exception final RecoverableFsDataOutputStream newRecoveredStream = writer.recover(recoverable2); newRecoveredStream.closeForCommit().commit(); }
Example 7
Source File: HadoopS3RecoverableWriterExceptionITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeAfterCommit() throws Exception { final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); stream.closeForCommit().commit(); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable); recoveredStream.closeForCommit().commit(); }
Example 8
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testCallingDeleteObjectTwiceDoesNotThroughException() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); boolean unsuccessfulDeletion = writer.cleanupRecoverableState(recoverable); Assert.assertFalse(unsuccessfulDeletion); }
Example 9
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 6 votes |
@Test(expected = FileNotFoundException.class) public void testCleanupRecoverableState() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); // this should throw the exception as we deleted the file. getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); }
Example 10
Source File: HadoopS3RecoverableWriterExceptionITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeWithWrongOffset() throws Exception { // this is a rather unrealistic scenario, but it is to trigger // truncation of the file and try to resume with missing data. final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable1 = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable2 = stream.persist(); stream.write(testData3.getBytes(StandardCharsets.UTF_8)); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable1); recoveredStream.closeForCommit().commit(); // this should throw an exception final RecoverableFsDataOutputStream newRecoveredStream = writer.recover(recoverable2); newRecoveredStream.closeForCommit().commit(); }
Example 11
Source File: HadoopS3RecoverableWriterExceptionITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test(expected = IOException.class) public void testResumeAfterCommit() throws Exception { final RecoverableWriter writer = getFileSystem().createRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(testData1.getBytes(StandardCharsets.UTF_8)); final RecoverableWriter.ResumeRecoverable recoverable = stream.persist(); stream.write(testData2.getBytes(StandardCharsets.UTF_8)); stream.closeForCommit().commit(); final RecoverableFsDataOutputStream recoveredStream = writer.recover(recoverable); recoveredStream.closeForCommit().commit(); }
Example 12
Source File: HadoopS3RecoverableWriterITCase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testCallingDeleteObjectTwiceDoesNotThroughException() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); S3Recoverable recoverable = (S3Recoverable) stream.persist(); stream.closeForCommit().commit(); // still the data is there as we have not deleted them from the tmp object final String content = getContentsOfFile(new Path('/' + recoverable.incompleteObjectName())); Assert.assertEquals(testData1, content); boolean successfullyDeletedState = writer.cleanupRecoverableState(recoverable); Assert.assertTrue(successfullyDeletedState); boolean unsuccessfulDeletion = writer.cleanupRecoverableState(recoverable); Assert.assertFalse(unsuccessfulDeletion); }
Example 13
Source File: HadoopRecoverableWriterOldHadoopWithNoTruncateSupportTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testExceptionThrownWhenRecoveringWithInProgressFile() throws IOException { final RecoverableWriter writerUnderTest = fileSystem.createRecoverableWriter(); final RecoverableFsDataOutputStream stream = writerUnderTest.open(new Path(basePath, "test-2")); final RecoverableWriter.ResumeRecoverable recoverable = stream.persist(); assertNotNull(recoverable); try { writerUnderTest.recover(recoverable); } catch (IOException e) { // this is the expected exception and we check also if the root cause is the hadoop < 2.7 version assertTrue(e.getCause() instanceof IllegalStateException); } }
Example 14
Source File: BucketStateSerializerTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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 15
Source File: BucketStateSerializerTest.java From flink with Apache License 2.0 | 5 votes |
@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 16
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCommitAfterPersist() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); stream.persist(); stream.write(bytesOf(testData2)); stream.closeForCommit().commit(); Assert.assertEquals(testData1 + testData2, getContentsOfFile(path)); }
Example 17
Source File: HadoopS3RecoverableWriterITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testCommitAfterPersist() throws Exception { final RecoverableWriter writer = getRecoverableWriter(); final Path path = new Path(basePathForTest, "part-0"); final RecoverableFsDataOutputStream stream = writer.open(path); stream.write(bytesOf(testData1)); stream.persist(); stream.write(bytesOf(testData2)); stream.closeForCommit().commit(); Assert.assertEquals(testData1 + testData2, getContentsOfFile(path)); }
Example 18
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 3 votes |
@Test public void testCommitAfterRecovery() throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final RecoverableFsDataOutputStream stream = initWriter.open(path); stream.write(bytesOf(testData1)); stream.persist(); stream.persist(); // and write some more data stream.write(bytesOf(testData2)); final RecoverableWriter.CommitRecoverable recoverable = stream.closeForCommit().getRecoverable(); final byte[] serializedRecoverable = initWriter.getCommitRecoverableSerializer().serialize(recoverable); // get a new serializer from a new writer to make sure that no pre-initialized state leaks in. final RecoverableWriter newWriter = getRecoverableWriter(); final SimpleVersionedSerializer<RecoverableWriter.CommitRecoverable> deserializer = newWriter.getCommitRecoverableSerializer(); final RecoverableWriter.CommitRecoverable recoveredRecoverable = deserializer.deserialize(deserializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream.Committer committer = newWriter.recoverForCommit(recoveredRecoverable); committer.commitAfterRecovery(); Assert.assertEquals(testData1 + testData2, getContentsOfFile(path)); }
Example 19
Source File: HadoopS3RecoverableWriterITCase.java From Flink-CEPplus with Apache License 2.0 | 3 votes |
@Test public void testCommitAfterRecovery() throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final RecoverableFsDataOutputStream stream = initWriter.open(path); stream.write(bytesOf(testData1)); stream.persist(); stream.persist(); // and write some more data stream.write(bytesOf(testData2)); final RecoverableWriter.CommitRecoverable recoverable = stream.closeForCommit().getRecoverable(); final byte[] serializedRecoverable = initWriter.getCommitRecoverableSerializer().serialize(recoverable); // get a new serializer from a new writer to make sure that no pre-initialized state leaks in. final RecoverableWriter newWriter = getRecoverableWriter(); final SimpleVersionedSerializer<RecoverableWriter.CommitRecoverable> deserializer = newWriter.getCommitRecoverableSerializer(); final RecoverableWriter.CommitRecoverable recoveredRecoverable = deserializer.deserialize(deserializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream.Committer committer = newWriter.recoverForCommit(recoveredRecoverable); committer.commitAfterRecovery(); Assert.assertEquals(testData1 + testData2, getContentsOfFile(path)); }
Example 20
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 3 votes |
@Test public void testCommitAfterRecovery() throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final RecoverableFsDataOutputStream stream = initWriter.open(path); stream.write(bytesOf(testData1)); stream.persist(); stream.persist(); // and write some more data stream.write(bytesOf(testData2)); final RecoverableWriter.CommitRecoverable recoverable = stream.closeForCommit().getRecoverable(); final byte[] serializedRecoverable = initWriter.getCommitRecoverableSerializer().serialize(recoverable); // get a new serializer from a new writer to make sure that no pre-initialized state leaks in. final RecoverableWriter newWriter = getRecoverableWriter(); final SimpleVersionedSerializer<RecoverableWriter.CommitRecoverable> deserializer = newWriter.getCommitRecoverableSerializer(); final RecoverableWriter.CommitRecoverable recoveredRecoverable = deserializer.deserialize(deserializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream.Committer committer = newWriter.recoverForCommit(recoveredRecoverable); committer.commitAfterRecovery(); Assert.assertEquals(testData1 + testData2, getContentsOfFile(path)); }