// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob.perf;

import com.azure.perf.test.core.RepeatingInputStream;
import com.azure.storage.blob.perf.core.AbstractUploadTest;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.ByteBuffer;

import static com.azure.perf.test.core.TestDataCreationHelper.createRandomByteBufferFlux;
import static com.azure.perf.test.core.TestDataCreationHelper.createRandomInputStream;

public class UploadBlockBlobTest extends AbstractUploadTest<BlobPerfStressOptions> {
    protected final RepeatingInputStream inputStream;
    protected final Flux<ByteBuffer> byteBufferFlux;

    public UploadBlockBlobTest(BlobPerfStressOptions options) {
        super(options);
        inputStream = (RepeatingInputStream) createRandomInputStream(options.getSize());
        inputStream.mark(Integer.MAX_VALUE);
        byteBufferFlux = createRandomByteBufferFlux(options.getSize());
    }

    @Override
    public void run() {
        inputStream.reset();
        blockBlobClient.upload(inputStream, options.getSize(), true);
    }

    @Override
    public Mono<Void> runAsync() {
        return blockBlobAsyncClient.upload(byteBufferFlux, options.getSize(), true)
            .then();
    }
}
