Search in sources :

Example 16 with GSBlobIdentifier

use of org.apache.flink.fs.gs.storage.GSBlobIdentifier in project flink by apache.

the class GSRecoverableFsDataOutputStreamTest method writeContent.

private void writeContent(ThrowingRunnable<IOException> write, byte[] expectedContent) throws IOException {
    // write the byte, confirm position change and existence of write channel
    assertEquals(position, fsDataOutputStream.getPos());
    write.run();
    assertEquals(position + expectedContent.length, fsDataOutputStream.getPos());
    // close and persist. there should be exactly zero blobs before and one after, with this
    // byte value in it
    assertEquals(0, blobStorage.blobs.size());
    fsDataOutputStream.closeForCommit();
    assertEquals(1, blobStorage.blobs.size());
    GSBlobIdentifier blobIdentifier = blobStorage.blobs.keySet().toArray(new GSBlobIdentifier[0])[0];
    MockBlobStorage.BlobValue blobValue = blobStorage.blobs.get(blobIdentifier);
    assertNotNull(blobValue);
    assertArrayEquals(expectedContent, blobValue.content);
}
Also used : GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) MockBlobStorage(org.apache.flink.fs.gs.storage.MockBlobStorage)

Example 17 with GSBlobIdentifier

use of org.apache.flink.fs.gs.storage.GSBlobIdentifier in project flink by apache.

the class GSCommitRecoverableTest method shouldGetComponentBlobIds.

@Test
public void shouldGetComponentBlobIds() {
    // configure options, if this test configuration has a temporary bucket name, set it
    Configuration flinkConfig = new Configuration();
    if (temporaryBucketName != null) {
        flinkConfig.set(GSFileSystemOptions.WRITER_TEMPORARY_BUCKET_NAME, temporaryBucketName);
    }
    GSFileSystemOptions options = new GSFileSystemOptions(flinkConfig);
    GSCommitRecoverable commitRecoverable = new GSCommitRecoverable(blobIdentifier, componentObjectIds);
    List<GSBlobIdentifier> componentBlobIdentifiers = commitRecoverable.getComponentBlobIds(options);
    for (int i = 0; i < componentObjectIds.size(); i++) {
        UUID componentObjectId = componentObjectIds.get(i);
        GSBlobIdentifier componentBlobIdentifier = componentBlobIdentifiers.get(i);
        // if a temporary bucket is specified in options, the component blob identifier
        // should be in this bucket; otherwise, it should be in the bucket with the final blob
        assertEquals(temporaryBucketName == null ? blobIdentifier.bucketName : temporaryBucketName, componentBlobIdentifier.bucketName);
        // make sure the name is what is expected
        String expectedObjectName = String.format(".inprogress/%s/%s/%s", blobIdentifier.bucketName, blobIdentifier.objectName, componentObjectId);
        assertEquals(expectedObjectName, componentBlobIdentifier.objectName);
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) UUID(java.util.UUID) GSFileSystemOptions(org.apache.flink.fs.gs.GSFileSystemOptions) Test(org.junit.Test)

Example 18 with GSBlobIdentifier

use of org.apache.flink.fs.gs.storage.GSBlobIdentifier in project flink by apache.

the class GSRecoverableWriterCommitterTest method before.

@Before
public void before() {
    Configuration flinkConfig = new Configuration();
    if (temporaryBucketName != null) {
        flinkConfig.set(GSFileSystemOptions.WRITER_TEMPORARY_BUCKET_NAME, temporaryBucketName);
    }
    options = new GSFileSystemOptions(flinkConfig);
    random = new Random();
    random.setSeed(TestUtils.RANDOM_SEED);
    blobStorage = new MockBlobStorage();
    blobIdentifier = new GSBlobIdentifier("foo", "bar");
    expectedBytes = new ByteArrayOutputStream();
}
Also used : Configuration(org.apache.flink.configuration.Configuration) Random(java.util.Random) GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) MockBlobStorage(org.apache.flink.fs.gs.storage.MockBlobStorage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GSFileSystemOptions(org.apache.flink.fs.gs.GSFileSystemOptions) Before(org.junit.Before)

Example 19 with GSBlobIdentifier

use of org.apache.flink.fs.gs.storage.GSBlobIdentifier in project flink by apache.

the class GSResumeRecoverableSerializerTest method shouldSerdeState.

@Test
public void shouldSerdeState() throws IOException {
    // create the state
    GSBlobIdentifier finalBlobIdentifier = new GSBlobIdentifier(bucketName, objectName);
    ArrayList<UUID> componentObjectIds = new ArrayList<>();
    for (int i = 0; i < componentCount; i++) {
        componentObjectIds.add(UUID.randomUUID());
    }
    GSResumeRecoverable state = new GSResumeRecoverable(finalBlobIdentifier, componentObjectIds, position, closed);
    // serialize and deserialize
    GSResumeRecoverableSerializer serializer = GSResumeRecoverableSerializer.INSTANCE;
    byte[] serialized = serializer.serialize(state);
    GSResumeRecoverable deserializedState = (GSResumeRecoverable) serializer.deserialize(serializer.getVersion(), serialized);
    // check that states match
    assertEquals(bucketName, deserializedState.finalBlobIdentifier.bucketName);
    assertEquals(objectName, deserializedState.finalBlobIdentifier.objectName);
    assertEquals(position, deserializedState.position);
    assertEquals(closed, deserializedState.closed);
    assertEquals(componentCount, deserializedState.componentObjectIds.size());
    for (int i = 0; i < componentCount; i++) {
        assertEquals(state.componentObjectIds.get(i), deserializedState.componentObjectIds.get(i));
    }
}
Also used : GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.Test)

Example 20 with GSBlobIdentifier

use of org.apache.flink.fs.gs.storage.GSBlobIdentifier in project flink by apache.

the class GSRecoverableWriterTest method before.

@Before
public void before() {
    MockBlobStorage storage = new MockBlobStorage();
    blobIdentifier = new GSBlobIdentifier("foo", "bar");
    Configuration flinkConfig = new Configuration();
    options = new GSFileSystemOptions(flinkConfig);
    writer = new GSRecoverableWriter(storage, options);
    componentObjectIds = new ArrayList<UUID>();
    for (int i = 0; i < componentCount; i++) {
        componentObjectIds.add(UUID.randomUUID());
    }
    resumeRecoverable = new GSResumeRecoverable(blobIdentifier, componentObjectIds, position, closed);
    commitRecoverable = new GSCommitRecoverable(blobIdentifier, componentObjectIds);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) GSBlobIdentifier(org.apache.flink.fs.gs.storage.GSBlobIdentifier) MockBlobStorage(org.apache.flink.fs.gs.storage.MockBlobStorage) UUID(java.util.UUID) GSFileSystemOptions(org.apache.flink.fs.gs.GSFileSystemOptions) Before(org.junit.Before)

Aggregations

GSBlobIdentifier (org.apache.flink.fs.gs.storage.GSBlobIdentifier)25 UUID (java.util.UUID)14 Test (org.junit.Test)11 Configuration (org.apache.flink.configuration.Configuration)9 GSFileSystemOptions (org.apache.flink.fs.gs.GSFileSystemOptions)8 MockBlobStorage (org.apache.flink.fs.gs.storage.MockBlobStorage)7 ArrayList (java.util.ArrayList)6 Before (org.junit.Before)5 Random (java.util.Random)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 MemorySize (org.apache.flink.configuration.MemorySize)1 Path (org.apache.flink.core.fs.Path)1 RecoverableFsDataOutputStream (org.apache.flink.core.fs.RecoverableFsDataOutputStream)1 RecoverableWriter (org.apache.flink.core.fs.RecoverableWriter)1 GSBlobStorage (org.apache.flink.fs.gs.storage.GSBlobStorage)1 GSRecoverableWriter (org.apache.flink.fs.gs.writer.GSRecoverableWriter)1