Skip to content

Commit 51bde0f

Browse files
committed
./gradlew spotlessApply
1 parent 16578b7 commit 51bde0f

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

disk-buffering/src/jmh/java/io/opentelemetry/contrib/disk/buffering/internal/files/utils/FileTransferUtilBenchmark.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
package io.opentelemetry.contrib.disk.buffering.internal.files.utils;
77

88
import io.opentelemetry.contrib.disk.buffering.internal.storage.files.utils.FileTransferUtil;
9+
import java.io.File;
10+
import java.io.FileInputStream;
11+
import java.io.IOException;
12+
import java.nio.file.Files;
13+
import java.nio.file.StandardOpenOption;
914
import org.openjdk.jmh.annotations.Benchmark;
1015
import org.openjdk.jmh.annotations.BenchmarkMode;
1116
import org.openjdk.jmh.annotations.Mode;
@@ -14,46 +19,39 @@
1419
import org.openjdk.jmh.annotations.State;
1520
import org.openjdk.jmh.annotations.TearDown;
1621

17-
import java.io.File;
18-
import java.io.FileInputStream;
19-
import java.io.IOException;
20-
import java.nio.file.Files;
21-
import java.nio.file.StandardOpenOption;
22-
2322
public class FileTransferUtilBenchmark {
2423

25-
@Benchmark
26-
@BenchmarkMode(Mode.AverageTime)
27-
public void fileTransfer(FileTransferState state)
28-
throws IOException {
29-
state.fileTransferUtil.transferBytes(state.offset, state.amountOfBytesToTransfer);
24+
@Benchmark
25+
@BenchmarkMode(Mode.AverageTime)
26+
public void fileTransfer(FileTransferState state) throws IOException {
27+
state.fileTransferUtil.transferBytes(state.offset, state.amountOfBytesToTransfer);
28+
}
29+
30+
@State(Scope.Benchmark)
31+
public static class FileTransferState {
32+
public FileTransferUtil fileTransferUtil;
33+
public int offset;
34+
public int amountOfBytesToTransfer;
35+
private File inputFile;
36+
private File outputFile;
37+
38+
@Setup
39+
public void setUp() throws IOException {
40+
outputFile = File.createTempFile("output", ".txt");
41+
inputFile = File.createTempFile("input", ".txt");
42+
int totalDataSize = 1024 * 1024; // 1MB
43+
byte[] data = new byte[totalDataSize];
44+
Files.write(inputFile.toPath(), data, StandardOpenOption.CREATE);
45+
fileTransferUtil = new FileTransferUtil(new FileInputStream(inputFile), outputFile);
46+
offset = 512;
47+
amountOfBytesToTransfer = totalDataSize - offset;
3048
}
3149

32-
@State(Scope.Benchmark)
33-
public static class FileTransferState {
34-
public FileTransferUtil fileTransferUtil;
35-
public int offset;
36-
public int amountOfBytesToTransfer;
37-
private File inputFile;
38-
private File outputFile;
39-
40-
@Setup
41-
public void setUp() throws IOException {
42-
outputFile = File.createTempFile("output", ".txt");
43-
inputFile = File.createTempFile("input", ".txt");
44-
int totalDataSize = 1024 * 1024; // 1MB
45-
byte[] data = new byte[totalDataSize];
46-
Files.write(inputFile.toPath(), data, StandardOpenOption.CREATE);
47-
fileTransferUtil = new FileTransferUtil(new FileInputStream(inputFile), outputFile);
48-
offset = 512;
49-
amountOfBytesToTransfer = totalDataSize - offset;
50-
}
51-
52-
@TearDown
53-
public void tearDown() throws IOException {
54-
fileTransferUtil.close();
55-
inputFile.delete();
56-
outputFile.delete();
57-
}
50+
@TearDown
51+
public void tearDown() throws IOException {
52+
fileTransferUtil.close();
53+
inputFile.delete();
54+
outputFile.delete();
5855
}
56+
}
5957
}

0 commit comments

Comments
 (0)