Java Code Examples for org.apache.flink.core.fs.RecoverableWriter#recover()
The following examples show how to use
org.apache.flink.core.fs.RecoverableWriter#recover() .
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: 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 2
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 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: 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 5
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 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: HadoopS3RecoverableWriterITCase.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testResumeAfterMultiplePersist( final String persistName, final String expectedFinalContents, final String firstItemToWrite, final String secondItemToWrite, final String thirdItemToWrite) throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final Map<String, RecoverableWriter.ResumeRecoverable> recoverables = new HashMap<>(4); try (final RecoverableFsDataOutputStream stream = initWriter.open(path)) { recoverables.put(INIT_EMPTY_PERSIST, stream.persist()); stream.write(bytesOf(firstItemToWrite)); recoverables.put(INTERM_WITH_STATE_PERSIST, stream.persist()); recoverables.put(INTERM_WITH_NO_ADDITIONAL_STATE_PERSIST, stream.persist()); // and write some more data stream.write(bytesOf(secondItemToWrite)); recoverables.put(FINAL_WITH_EXTRA_STATE, stream.persist()); } final SimpleVersionedSerializer<RecoverableWriter.ResumeRecoverable> serializer = initWriter.getResumeRecoverableSerializer(); final byte[] serializedRecoverable = serializer.serialize(recoverables.get(persistName)); // 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.ResumeRecoverable> deserializer = newWriter.getResumeRecoverableSerializer(); final RecoverableWriter.ResumeRecoverable recoveredRecoverable = deserializer.deserialize(serializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream recoveredStream = newWriter.recover(recoveredRecoverable); recoveredStream.write(bytesOf(thirdItemToWrite)); recoveredStream.closeForCommit().commit(); Assert.assertEquals(expectedFinalContents, getContentsOfFile(path)); }
Example 8
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 5 votes |
private void testResumeAfterMultiplePersist( final String persistName, final String expectedFinalContents, final String firstItemToWrite, final String secondItemToWrite, final String thirdItemToWrite) throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final Map<String, RecoverableWriter.ResumeRecoverable> recoverables = new HashMap<>(4); try (final RecoverableFsDataOutputStream stream = initWriter.open(path)) { recoverables.put(INIT_EMPTY_PERSIST, stream.persist()); stream.write(bytesOf(firstItemToWrite)); recoverables.put(INTERM_WITH_STATE_PERSIST, stream.persist()); recoverables.put(INTERM_WITH_NO_ADDITIONAL_STATE_PERSIST, stream.persist()); // and write some more data stream.write(bytesOf(secondItemToWrite)); recoverables.put(FINAL_WITH_EXTRA_STATE, stream.persist()); } final SimpleVersionedSerializer<RecoverableWriter.ResumeRecoverable> serializer = initWriter.getResumeRecoverableSerializer(); final byte[] serializedRecoverable = serializer.serialize(recoverables.get(persistName)); // 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.ResumeRecoverable> deserializer = newWriter.getResumeRecoverableSerializer(); final RecoverableWriter.ResumeRecoverable recoveredRecoverable = deserializer.deserialize(serializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream recoveredStream = newWriter.recover(recoveredRecoverable); recoveredStream.write(bytesOf(thirdItemToWrite)); recoveredStream.closeForCommit().commit(); Assert.assertEquals(expectedFinalContents, getContentsOfFile(path)); }
Example 9
Source File: HadoopS3RecoverableWriterITCase.java From flink with Apache License 2.0 | 5 votes |
private void testResumeAfterMultiplePersist( final String persistName, final String expectedFinalContents, final String firstItemToWrite, final String secondItemToWrite, final String thirdItemToWrite) throws Exception { final Path path = new Path(basePathForTest, "part-0"); final RecoverableWriter initWriter = getRecoverableWriter(); final Map<String, RecoverableWriter.ResumeRecoverable> recoverables = new HashMap<>(4); try (final RecoverableFsDataOutputStream stream = initWriter.open(path)) { recoverables.put(INIT_EMPTY_PERSIST, stream.persist()); stream.write(bytesOf(firstItemToWrite)); recoverables.put(INTERM_WITH_STATE_PERSIST, stream.persist()); recoverables.put(INTERM_WITH_NO_ADDITIONAL_STATE_PERSIST, stream.persist()); // and write some more data stream.write(bytesOf(secondItemToWrite)); recoverables.put(FINAL_WITH_EXTRA_STATE, stream.persist()); } final SimpleVersionedSerializer<RecoverableWriter.ResumeRecoverable> serializer = initWriter.getResumeRecoverableSerializer(); final byte[] serializedRecoverable = serializer.serialize(recoverables.get(persistName)); // 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.ResumeRecoverable> deserializer = newWriter.getResumeRecoverableSerializer(); final RecoverableWriter.ResumeRecoverable recoveredRecoverable = deserializer.deserialize(serializer.getVersion(), serializedRecoverable); final RecoverableFsDataOutputStream recoveredStream = newWriter.recover(recoveredRecoverable); recoveredStream.write(bytesOf(thirdItemToWrite)); recoveredStream.closeForCommit().commit(); Assert.assertEquals(expectedFinalContents, getContentsOfFile(path)); }
Example 10
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); } }