Skip to content

Commit 86edc29

Browse files
Tweaks
1 parent cb53fb0 commit 86edc29

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/main/java/fr/bl/drit/flow/agent/BinaryThreadRecorder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ protected void writeVarInt(long value) throws IOException {
245245
* @param value The positive integer to encode
246246
* @throws IOException If an I/O error occurs when writing to file.
247247
*/
248-
protected void writeFlagAndVarInt(int flag, long value) throws IOException {
248+
protected void writeFlagAndVarInt(byte flag, long value) throws IOException {
249249
// Extract lowest 6 bits for first byte
250250
int firstPayload = (int) (value & M_PACK_PAYLOAD); // 6 bits
251251
value >>>= 6;

src/main/java/fr/bl/drit/flow/agent/FlowAdvice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import net.bytebuddy.asm.Advice;
55

66
/**
7-
* Contains the enter and exit {@link net.bytebuddy.asm.Advice Advice} methods. Their code is
8-
* inserted at the start and end of instrumented methods, respectively.
7+
* Contains the enter and exit {@link Advice} methods. Their code is inserted at the start and end
8+
* of instrumented methods, respectively.
99
*/
1010
public final class FlowAdvice {
1111

src/main/java/fr/bl/drit/flow/agent/Recorder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
/** Specifies a recorder that is used to record flow data. */
77
public interface Recorder extends Closeable {
8+
89
/**
910
* Emit a method enter event with the given method ID.
1011
*

src/main/java/fr/bl/drit/flow/agent/ThreadLocalRecorder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
import java.io.IOException;
44
import java.nio.file.Path;
5-
import java.util.Queue;
5+
import java.util.Collection;
66
import java.util.concurrent.ConcurrentLinkedQueue;
77

88
/** A recorder that orchestrates per-thread recorders. */
99
public final class ThreadLocalRecorder implements Recorder {
1010

1111
private final ThreadLocal<ThreadRecorder> local;
12-
private final Queue<ThreadRecorder> all = new ConcurrentLinkedQueue<>();
12+
private final Collection<ThreadRecorder> all = new ConcurrentLinkedQueue<>();
1313

1414
/**
1515
* @param factory Responsible for creating {@link ThreadRecorder}s
1616
* @param outputDir Path to the output directory
1717
*/
18-
public ThreadLocalRecorder(ThreadRecorderFactory factory, Path outputDir) {
18+
public ThreadLocalRecorder(final ThreadRecorderFactory factory, final Path outputDir) {
1919
this.local =
2020
ThreadLocal.withInitial(
2121
() -> {

src/test/java/fr/bl/drit/flow/agent/BinaryThreadRecorderTest.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,42 @@ private static Object[] readFlagAndVarInt(InputStream in) throws IOException {
9999
}
100100

101101
@Test
102-
public void testWriteVarInt_smallValues() throws Exception {
102+
public void testWriteVarInt_noContinuation() throws Exception {
103103
String outputPath = null;
104104
try (BinaryThreadRecorder rec = new BinaryThreadRecorder(tempDir)) {
105105
outputPath = rec.getFileName();
106106
rec.writeVarInt(0L);
107107
rec.writeVarInt(1L);
108108
rec.writeVarInt(127L);
109-
rec.writeVarInt(128L);
110-
rec.writeVarInt(300L);
111-
rec.writeVarInt(Long.MAX_VALUE);
112109
}
113110

114111
byte[] actual = Files.readAllBytes(tempDir.resolve(outputPath));
115112

116113
byte[] e0 = leb128Expected(0L); // 00
117114
byte[] e1 = leb128Expected(1L); // 01
118115
byte[] e127 = leb128Expected(127L); // 7F
116+
117+
byte[] expected = concat(e0, e1, e127);
118+
assertBytesEquals(expected, actual);
119+
}
120+
121+
@Test
122+
public void testWriteVarInt_withContinuation() throws Exception {
123+
String outputPath = null;
124+
try (BinaryThreadRecorder rec = new BinaryThreadRecorder(tempDir)) {
125+
outputPath = rec.getFileName();
126+
rec.writeVarInt(128L);
127+
rec.writeVarInt(300L);
128+
rec.writeVarInt(Long.MAX_VALUE);
129+
}
130+
131+
byte[] actual = Files.readAllBytes(tempDir.resolve(outputPath));
132+
119133
byte[] e128 = leb128Expected(128L); // 80 01
120134
byte[] e300 = leb128Expected(300L); // AC 02
121135
byte[] eMax = leb128Expected(Long.MAX_VALUE);
122136

123-
byte[] expected = concat(e0, e1, e127, e128, e300, eMax);
137+
byte[] expected = concat(e128, e300, eMax);
124138
assertBytesEquals(expected, actual);
125139
}
126140

0 commit comments

Comments
 (0)