Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ulyp.core.recorders.ObjectRecorderRegistry;
import com.ulyp.core.recorders.PrintingRecorder;
import com.ulyp.core.recorders.arrays.ByteArrayRecorder;
import com.ulyp.core.recorders.arrays.IntArrayRecorder;
import com.ulyp.core.recorders.arrays.ObjectArrayRecorder;
import com.ulyp.core.recorders.collections.*;

Expand All @@ -29,11 +30,14 @@ private void configurePrintingRecorder() {
private void configureArrayRecorders() {
ByteArrayRecorder byteArrayRecorder = (ByteArrayRecorder) ObjectRecorderRegistry.BYTE_ARRAY_RECORDER.getInstance();
ObjectArrayRecorder objectArrayRecorder = (ObjectArrayRecorder) ObjectRecorderRegistry.OBJECT_ARRAY_RECORDER.getInstance();
IntArrayRecorder intArrayRecorder = (IntArrayRecorder) ObjectRecorderRegistry.INT_ARRAY_RECORDER.getInstance();
if (options.getArraysRecordingOption().get()) {
objectArrayRecorder.setEnabled(true);
byteArrayRecorder.setEnabled(true);
intArrayRecorder.setEnabled(true);
}
objectArrayRecorder.setMaxItemsToRecord(options.getMaxItemsArrayRecordingOption().get());
intArrayRecorder.setMaxItemsToRecord(options.getMaxItemsArrayRecordingOption().get());
}

private void configureCollectionRecorders() {
Expand Down
3 changes: 3 additions & 0 deletions ulyp-agent-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ buildscript {

plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.6.21'
id 'org.jetbrains.kotlin.plugin.lombok' version '1.6.21'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.21'
id "io.freefair.lombok" version "6.0.0-m2"
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.agent.tests.util;

import com.ulyp.core.Method;
import com.ulyp.core.recorders.IdentityObjectRecord;
import com.ulyp.core.recorders.basic.NullObjectRecord;
import com.ulyp.core.recorders.numeric.IntegralRecord;
import com.ulyp.core.recorders.ObjectRecord;
import com.ulyp.core.recorders.StringObjectRecord;
import com.ulyp.core.recorders.basic.StringObjectRecord;
import com.ulyp.storage.tree.CallRecord;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
Expand All @@ -25,6 +28,62 @@ public void describeTo(Description description) {
};
}

public static Matcher<ObjectRecord> isIdentity(String expectedType) {
return new TypeSafeMatcher<ObjectRecord>() {
@Override
protected boolean matchesSafely(ObjectRecord item) {
return item instanceof IdentityObjectRecord && item.getType().getName().equals(expectedType);
}

@Override
public void describeTo(Description description) {
description.appendText("is recorded identity with type ").appendValue(expectedType);
}
};
}

public static Matcher<ObjectRecord> isIdentity() {
return new TypeSafeMatcher<ObjectRecord>() {
@Override
protected boolean matchesSafely(ObjectRecord item) {
return item instanceof IdentityObjectRecord;
}

@Override
public void describeTo(Description description) {
description.appendText("is recorded identity with any type");
}
};
}

public static Matcher<ObjectRecord> isIntegral(long expectedValue) {
return new TypeSafeMatcher<ObjectRecord>() {
@Override
protected boolean matchesSafely(ObjectRecord item) {
return item instanceof IntegralRecord && ((IntegralRecord) item).getValue() == expectedValue;
}

@Override
public void describeTo(Description description) {
description.appendText("is recorded integral value with type ").appendValue(expectedValue);
}
};
}

public static Matcher<ObjectRecord> isNull() {
return new TypeSafeMatcher<ObjectRecord>() {
@Override
protected boolean matchesSafely(ObjectRecord item) {
return item instanceof NullObjectRecord;
}

@Override
public void describeTo(Description description) {
description.appendText("is null");
}
};
}

public static Matcher<Method> hasName(String name) {
return new TypeSafeMatcher<Method>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConcurrentInstrumentationTest extends AbstractInstrumentationTest {
void shouldInstrumentConcurrently() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(TestRunner.class)
.withMain(TestRunner.class)
.withMethodToRecord(MethodMatcher.parse("**.zxczxc.*"))
.withLogLevel("OFF")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ConcurrentMidSizeRecordingTest extends AbstractInstrumentationTest {
void shouldRecordInConcurrentMode() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(MultithreadedExample.class)
.withMain(MultithreadedExample.class)
.withMethodToRecord(MethodMatcher.parse("**.RecordedRunner.run"))
.withLogLevel("OFF")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ConcurrentRecordingTest extends AbstractInstrumentationTest {
void shouldRecordInConcurrentMode() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(MultithreadedExample.class)
.withMain(MultithreadedExample.class)
.withMethodToRecord(MethodMatcher.parse("*.*"))
.withLogLevel("OFF")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DirectMemLeakTest extends AbstractInstrumentationTest {
void shouldWithstandLongRecording() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(FibonacciTestCase.class)
.withMain(FibonacciTestCase.class)
.withMethodToRecord("compute")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ExcludeClassesInstrumentationTest extends AbstractInstrumentationTest {
void shouldNotExcludeAnyClassesIfOptionIsNotSet() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
);


Expand All @@ -32,7 +32,7 @@ void shouldNotExcludeAnyClassesIfOptionIsNotSet() {
void shouldExcludeFromInstrumentationOneClass() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withExcludeClassesProperty("com.agent.tests.general.a.b.B")
);

Expand All @@ -46,7 +46,7 @@ void shouldExcludeFromInstrumentationOneClass() {
void shouldExcludeFromInstrumentationOneClassByInterface() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withExcludeClassesProperty("**.BInterface")
);

Expand All @@ -59,7 +59,7 @@ void shouldExcludeFromInstrumentationOneClassByInterface() {
void shouldExcludeTwoClassesFromInstrumentation() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withExcludeClassesProperty("com.agent.tests.general.a.b.B, com.agent.tests.general.a.c.C")
);

Expand All @@ -71,7 +71,7 @@ void shouldExcludeTwoClassesFromInstrumentation() {
void shouldExcludeOneClassFromInstrumentationByAntPattern() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withExcludeClassesProperty("com.agent.tests.general.a.b.**")
);

Expand All @@ -83,7 +83,7 @@ void shouldExcludeOneClassFromInstrumentationByAntPattern() {
void shouldExcludeTwoClassesFromInstrumentationByAntPattern() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withExcludeClassesProperty("com.agent.tests.general.a.b.**, com.agent.tests.general.a.c.**")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void main(String[] args) {
void shouldRecordNormalCase() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withMethodToRecord(MethodMatcher.parse("**.A.main"))
);

Expand All @@ -40,7 +40,7 @@ void shouldRecordNormalCase() {
void shouldNotStartRecordingIfMethodExcluded() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withMethodToRecord(MethodMatcher.parse("**.A.foo,**.A.bar,-**.A.foo"))
);

Expand All @@ -51,7 +51,7 @@ void shouldNotStartRecordingIfMethodExcluded() {
void shouldNotStartRecordingIfMethodExcluded2() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withMethodToRecord(MethodMatcher.parse("**.A.*,-**.A.main"))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MultipleCallsInstrumentationTest extends AbstractInstrumentationTest {
void shouldMake1000Calls() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(TestCase.class)
.withMain(TestCase.class)
.withMethodToRecord("make1000CallsInLoop")
);

Expand All @@ -28,7 +28,7 @@ void shouldMake1000Calls() {
void shouldHaveCompleteTree() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(TestCase.class)
.withMain(TestCase.class)
.withMethodToRecord("level0")
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PackageFilterInstrumentationTest extends AbstractInstrumentationTest {
void shouldInstrumentAndTraceAllClasses() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withInstrumentedPackages("com.agent.tests.general.a")
);

Expand All @@ -30,7 +30,7 @@ void shouldInstrumentAndTraceAllClasses() {
void shouldExcludeInstrumentationPackage() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withInstrumentedPackages("com.agent.tests.general.a")
.withExcludedFromInstrumentationPackages("com.agent.tests.general.a.b")
);
Expand All @@ -49,7 +49,7 @@ void shouldExcludeInstrumentationPackage() {
void shouldExcludeTwoPackages() {
CallRecord root = runSubprocessAndReadFile(
new ForkProcessBuilder()
.withMainClassName(A.class)
.withMain(A.class)
.withInstrumentedPackages("com.agent.tests.general.a")
.withExcludedFromInstrumentationPackages("com.agent.tests.general.a.b", "com.agent.tests.general.a.c")
.withLogLevel("INFO")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RecordAllTest extends AbstractInstrumentationTest {
void shouldRecordAllMethods() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(MultithreadedExample.class)
.withMain(MultithreadedExample.class)
.withMethodToRecord(MethodMatcher.parse("*.*"))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.agent.tests.util.AbstractInstrumentationTest;
import com.agent.tests.util.ForkProcessBuilder;
import com.agent.tests.util.RecordingResult;
import com.ulyp.core.recorders.NumberRecord;
import com.ulyp.core.recorders.StringObjectRecord;
import com.ulyp.core.recorders.basic.StringObjectRecord;
import com.ulyp.core.recorders.numeric.IntegralRecord;
import com.ulyp.core.util.MethodMatcher;
import com.ulyp.storage.tree.CallRecord;
import org.hamcrest.Matchers;
Expand All @@ -19,7 +19,7 @@ class RecordNestedCallsTest extends AbstractInstrumentationTest {
void shouldRecordAllMethods() {
RecordingResult recordingResult = runSubprocess(
new ForkProcessBuilder()
.withMainClassName(TestCase.class)
.withMain(TestCase.class)
.withMethodToRecord(MethodMatcher.parse("**.TestCase.startRecordingFoo"))
);

Expand All @@ -33,15 +33,15 @@ void shouldRecordAllMethods() {
assertThat(nestedCallRecord2.getArgs(), Matchers.hasSize(2));
assertThat(nestedCallRecord2.getArgs(), allOf(
hasItem(instanceOf(StringObjectRecord.class)),
hasItem(instanceOf(NumberRecord.class)))
hasItem(instanceOf(IntegralRecord.class)))
);

CallRecord nestedCallRecord3 = nestedCallRecord2.getChildren().get(0);
assertThat(nestedCallRecord3.getArgs(), Matchers.hasSize(3));
assertThat(nestedCallRecord3.getArgs(), allOf(
hasItem(instanceOf(StringObjectRecord.class)),
hasItem(instanceOf(NumberRecord.class)),
hasItem(instanceOf(NumberRecord.class)))
hasItem(instanceOf(IntegralRecord.class)),
hasItem(instanceOf(IntegralRecord.class)))
);
}

Expand Down
Loading