|
18 | 18 |
|
19 | 19 | import com.google.cloud.storage.Blob; |
20 | 20 | import com.google.cloud.storage.BlobInfo; |
| 21 | +import com.google.cloud.storage.DataGenerator; |
21 | 22 | import com.google.cloud.storage.Storage; |
22 | 23 | import com.google.cloud.storage.TmpFile; |
| 24 | +import java.io.PrintWriter; |
23 | 25 | import java.nio.file.Path; |
24 | | -import java.nio.file.Paths; |
25 | 26 | import java.time.Clock; |
26 | 27 | import java.time.Duration; |
27 | 28 | import java.time.Instant; |
28 | 29 | import java.util.concurrent.Callable; |
29 | 30 |
|
30 | | -final class Workload1 implements Callable<String> { |
31 | | - private final TmpFile file; |
32 | | - private final BlobInfo blob; |
| 31 | +final class W1R3 implements Callable<String> { |
| 32 | + |
33 | 33 | private final Storage storage; |
34 | 34 | private final int workers; |
35 | 35 | private final String api; |
| 36 | + private final PrintWriter printWriter; |
| 37 | + private final int objectSize; |
| 38 | + private final Path tempDirectory; |
| 39 | + private final String bucketName; |
36 | 40 |
|
37 | | - Workload1(TmpFile file, BlobInfo blob, Storage storage, int workers, String api) { |
38 | | - this.file = file; |
39 | | - this.blob = blob; |
| 41 | + W1R3( |
| 42 | + Storage storage, |
| 43 | + int workers, |
| 44 | + String api, |
| 45 | + PrintWriter printWriter, |
| 46 | + int objectSize, |
| 47 | + Path tempDirectory, |
| 48 | + String bucketName) { |
40 | 49 | this.storage = storage; |
41 | 50 | this.workers = workers; |
42 | 51 | this.api = api; |
| 52 | + this.printWriter = printWriter; |
| 53 | + this.objectSize = objectSize; |
| 54 | + this.tempDirectory = tempDirectory; |
| 55 | + this.bucketName = bucketName; |
43 | 56 | } |
44 | 57 |
|
45 | 58 | @Override |
46 | 59 | public String call() throws Exception { |
47 | | - Clock clock = Clock.systemDefaultZone(); |
| 60 | + // Create the file to be uploaded and fill it with data |
| 61 | + TmpFile file = DataGenerator.base64Characters().tempFile(tempDirectory, objectSize); |
| 62 | + BlobInfo blob = BlobInfo.newBuilder(bucketName, file.toString()).build(); |
48 | 63 |
|
49 | 64 | // Get the start time |
| 65 | + Clock clock = Clock.systemDefaultZone(); |
50 | 66 | Instant startTime = clock.instant(); |
51 | 67 | Blob created = storage.createFrom(blob, file.getPath()); |
52 | 68 | Instant endTime = clock.instant(); |
53 | 69 | Duration elapsedTimeUpload = Duration.between(startTime, endTime); |
54 | | - System.out.println( |
| 70 | + printWriter.println( |
55 | 71 | generateCloudMonitoringResult( |
56 | 72 | "WRITE", |
57 | 73 | StorageSharedBenchmarkingUtils.calculateThroughput( |
58 | 74 | created.getSize().longValue(), elapsedTimeUpload), |
59 | 75 | created) |
60 | 76 | .toString()); |
61 | | - Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); |
62 | 77 | for (int i = 0; i <= StorageSharedBenchmarkingUtils.DEFAULT_NUMBER_OF_READS; i++) { |
63 | | - TmpFile dest = TmpFile.of(tempDir, "prefix", "bin"); |
| 78 | + TmpFile dest = TmpFile.of(tempDirectory, "prefix", "bin"); |
64 | 79 | startTime = clock.instant(); |
65 | 80 | storage.downloadTo(created.getBlobId(), dest.getPath()); |
66 | 81 | endTime = clock.instant(); |
67 | 82 | Duration elapsedTimeDownload = Duration.between(startTime, endTime); |
68 | | - System.out.println( |
| 83 | + printWriter.println( |
69 | 84 | generateCloudMonitoringResult( |
70 | 85 | "READ[" + i + "]", |
71 | 86 | StorageSharedBenchmarkingUtils.calculateThroughput( |
|
0 commit comments