Java Code Examples for net.bytebuddy.utility.RandomString#make()

The following examples show how to use net.bytebuddy.utility.RandomString#make() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonTest.java    From redisson with Apache License 2.0 6 votes vote down vote up
public void testLeak() throws InterruptedException {
    Config config = new Config();
    config.useSingleServer()
          .setAddress(RedisRunner.getDefaultRedisServerBindAddressAndPort());

    RedissonClient localRedisson = Redisson.create(config);

    String key = RandomString.make(120);
    for (int i = 0; i < 500; i++) {
        RMapCache<String, String> cache = localRedisson.getMapCache("mycache");
        RLock keyLock = cache.getLock(key);
        keyLock.lockInterruptibly(10, TimeUnit.SECONDS);
        try {
            cache.get(key);
            cache.put(key, RandomString.make(4*1024*1024), 5, TimeUnit.SECONDS);
        } finally {
            if (keyLock != null) {
                keyLock.unlock();
            }
        }
    }
    

}
 
Example 2
Source File: Implementation.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new default implementation context.
 *
 * @param instrumentedType            The description of the type that is currently subject of creation.
 * @param classFileVersion            The class file version of the created class.
 * @param auxiliaryTypeNamingStrategy The naming strategy for naming an auxiliary type.
 * @param typeInitializer             The type initializer of the created instrumented type.
 * @param auxiliaryClassFileVersion   The class file version to use for auxiliary classes.
 */
protected Default(TypeDescription instrumentedType,
                  ClassFileVersion classFileVersion,
                  AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                  TypeInitializer typeInitializer,
                  ClassFileVersion auxiliaryClassFileVersion) {
    super(instrumentedType, classFileVersion);
    this.auxiliaryTypeNamingStrategy = auxiliaryTypeNamingStrategy;
    this.typeInitializer = typeInitializer;
    this.auxiliaryClassFileVersion = auxiliaryClassFileVersion;
    registeredAccessorMethods = new HashMap<SpecialMethodInvocation, DelegationRecord>();
    registeredGetters = new HashMap<FieldDescription, DelegationRecord>();
    registeredSetters = new HashMap<FieldDescription, DelegationRecord>();
    auxiliaryTypes = new HashMap<AuxiliaryType, DynamicType>();
    registeredFieldCacheEntries = new HashMap<FieldCacheEntry, FieldDescription.InDefinedShape>();
    registeredFieldCacheFields = new HashSet<FieldDescription.InDefinedShape>();
    suffix = RandomString.make();
    fieldCacheCanAppendEntries = true;
}
 
Example 3
Source File: ClassReloadingStrategyTest.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Test
@AgentAttachmentRule.Enforce(retransformsClasses = true)
@JavaVersionRule.Enforce(atMost = 10) // Wait for mechanism in sun.misc.Unsafe to define class.
public void testFromAgentClassWithAuxiliaryReloadingStrategy() throws Exception {
    assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
    Foo foo = new Foo();
    assertThat(foo.foo(), is(FOO));
    ClassReloadingStrategy classReloadingStrategy = ClassReloadingStrategy.fromInstalledAgent();
    String randomName = FOO + RandomString.make();
    new ByteBuddy()
            .redefine(Foo.class)
            .method(named(FOO))
            .intercept(FixedValue.value(BAR))
            .make()
            .include(new ByteBuddy().subclass(Object.class).name(randomName).make())
            .load(Foo.class.getClassLoader(), classReloadingStrategy);
    try {
        assertThat(foo.foo(), is(BAR));
    } finally {
        classReloadingStrategy.reset(Foo.class);
        assertThat(foo.foo(), is(FOO));
    }
    assertThat(Class.forName(randomName), notNullValue(Class.class));
}
 
Example 4
Source File: LaunchShortcutTest.java    From dartboard with Eclipse Public License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void launchShortcut__DartProjectNoLaunchConfig__NewLaunchConfigIsCreated() throws Exception {
	String projectName = RandomString.make(8);
	String mainClass = RandomString.make(4) + ".dart";
	ProjectUtil.createDartProject(projectName);

	ProjectExplorer projectExplorer = new ProjectExplorer();
	projectExplorer.open();
	projectExplorer.getProject(projectName).select();

	new ContextMenuItem(new WithMnemonicTextMatcher("Run As"), new RegexMatcher("\\d Run as Dart Program"))
			.select();

	new WaitUntil(new ShellIsActive("Edit Configuration"));
	new LabeledCombo("Project:").setSelection(projectName);
	new LabeledText("Main class:").setText(mainClass);
	new PushButton("Run").click();
	ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();

	// Find last launch configuration for selected project.
	ILaunchConfiguration launchConfiguration = null;
	for (ILaunchConfiguration conf : manager.getLaunchConfigurations()) {
		if (conf.getAttribute(Constants.LAUNCH_SELECTED_PROJECT, "").equalsIgnoreCase(projectName)) { //$NON-NLS-1$
			launchConfiguration = conf;
		}
	}

	assertNotNull(launchConfiguration);
	assertEquals(launchConfiguration.getAttribute("main_class", ""), mainClass);

	// Cleanup
	launchConfiguration.delete();
}
 
Example 5
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSnappyBig() throws IOException {
    SnappyCodec sc = new SnappyCodec();
    String randomData = RandomString.make(Short.MAX_VALUE*2 + 142);
    ByteBuf g = sc.getValueEncoder().encode(randomData);
    String decompressedData = (String) sc.getValueDecoder().decode(g, null);
    assertThat(decompressedData).isEqualTo(randomData);
}
 
Example 6
Source File: RedissonCodecTest.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Test
public void testSnappyBigV2() throws IOException {
    Codec sc = new SnappyCodecV2();
    String randomData = RandomString.make(Short.MAX_VALUE*2 + 142);
    ByteBuf g = sc.getValueEncoder().encode(randomData);
    String decompressedData = (String) sc.getValueDecoder().decode(g, null);
    assertThat(decompressedData).isEqualTo(randomData);
}
 
Example 7
Source File: DynamicTypeDefaultTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
private static File makeTemporaryFolder() throws IOException {
    File file = File.createTempFile(TEMP, TEMP);
    try {
        File folder = new File(file.getParentFile(), TEMP + RandomString.make());
        assertThat(folder.mkdir(), is(true));
        return folder;
    } finally {
        assertThat(file.delete(), is(true));
    }
}
 
Example 8
Source File: ClassInjectorUsingInstrumentationTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@AgentAttachmentRule.Enforce
public void testSystemInjection() throws Exception {
    ClassInjector classInjector = ClassInjector.UsingInstrumentation.of(folder,
            ClassInjector.UsingInstrumentation.Target.SYSTEM,
            ByteBuddyAgent.install());
    String name = BAR + RandomString.make();
    DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
    Map<TypeDescription, Class<?>> types = classInjector.inject(Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
    assertThat(types.size(), is(1));
    assertThat(types.get(dynamicType.getTypeDescription()).getName(), is(name));
    assertThat(types.get(dynamicType.getTypeDescription()).getClassLoader(), is(ClassLoader.getSystemClassLoader()));
}
 
Example 9
Source File: ClassInjectorUsingInstrumentationTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@AgentAttachmentRule.Enforce
public void testBootstrapInjection() throws Exception {
    ClassInjector classInjector = ClassInjector.UsingInstrumentation.of(folder,
            ClassInjector.UsingInstrumentation.Target.BOOTSTRAP,
            ByteBuddyAgent.install());
    String name = FOO + RandomString.make();
    DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
    Map<TypeDescription, Class<?>> types = classInjector.inject(Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
    assertThat(types.size(), is(1));
    assertThat(types.get(dynamicType.getTypeDescription()).getName(), is(name));
    assertThat(types.get(dynamicType.getTypeDescription()).getClassLoader(), nullValue(ClassLoader.class));
}
 
Example 10
Source File: ClassInjectorUsingInstrumentationTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    File file = File.createTempFile(FOO, BAR);
    assertThat(file.delete(), is(true));
    folder = new File(file.getParentFile(), RandomString.make());
    assertThat(folder.mkdir(), is(true));
}
 
Example 11
Source File: ClassLoadingStrategyForBootstrapInjectionTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@AgentAttachmentRule.Enforce
public void testBootstrapInjection() throws Exception {
    ClassLoadingStrategy<ClassLoader> bootstrapStrategy = new ClassLoadingStrategy.ForBootstrapInjection(ByteBuddyAgent.install(), file);
    String name = FOO + RandomString.make();
    DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
    Map<TypeDescription, Class<?>> loaded = bootstrapStrategy.load(ClassLoadingStrategy.BOOTSTRAP_LOADER, Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
    assertThat(loaded.size(), is(1));
    assertThat(loaded.get(dynamicType.getTypeDescription()).getName(), is(name));
    assertThat(loaded.get(dynamicType.getTypeDescription()).getClassLoader(), nullValue(ClassLoader.class));
}
 
Example 12
Source File: ClassLoadingStrategyForBootstrapInjectionTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@AgentAttachmentRule.Enforce
@ClassReflectionInjectionAvailableRule.Enforce
public void testClassLoaderInjection() throws Exception {
    ClassLoadingStrategy<ClassLoader> bootstrapStrategy = new ClassLoadingStrategy.ForBootstrapInjection(ByteBuddyAgent.install(), file);
    String name = BAR + RandomString.make();
    ClassLoader classLoader = new URLClassLoader(new URL[0], null);
    DynamicType dynamicType = new ByteBuddy().subclass(Object.class).name(name).make();
    Map<TypeDescription, Class<?>> loaded = bootstrapStrategy.load(classLoader, Collections.singletonMap(dynamicType.getTypeDescription(), dynamicType.getBytes()));
    assertThat(loaded.size(), is(1));
    assertThat(loaded.get(dynamicType.getTypeDescription()).getName(), is(name));
    assertThat(loaded.get(dynamicType.getTypeDescription()).getClassLoader(), is(classLoader));
}
 
Example 13
Source File: PubGetHandlerTest.java    From dartboard with Eclipse Public License 2.0 4 votes vote down vote up
@Before
public void setup() {
	projectName = RandomString.make(8);
}
 
Example 14
Source File: MethodNameTransformer.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new suffixing method name transformer which adds a default suffix with a random name component.
 *
 * @return A method name transformer that adds a randomized suffix to the original method name.
 */
public static MethodNameTransformer withRandomSuffix() {
    return new Suffixing(DEFAULT_SUFFIX + RandomString.make());
}
 
Example 15
Source File: InvokeDynamic.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new argument provider that stores the given value in a static field.
 *
 * @param value     The value that is to be provided to the bootstrapped method.
 * @param fieldType The type of the field which is also provided to the bootstrap method.
 */
protected ForInstance(Object value, TypeDescription fieldType) {
    this.value = value;
    this.fieldType = fieldType;
    name = FIELD_PREFIX + "$" + RandomString.make();
}
 
Example 16
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new target handler for a static field.
 *
 * @param target    The target on which the method is to be invoked.
 * @param fieldType The type of the field.
 */
protected Factory(Object target, TypeDescription.Generic fieldType) {
    this.target = target;
    this.fieldType = fieldType;
    name = FIELD_PREFIX + "$" + RandomString.make();
}
 
Example 17
Source File: MethodCall.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a factory that loads the value of a static field as an argument.
 *
 * @param value The value to supply as an argument.
 */
public Factory(Object value) {
    this.value = value;
    name = FIELD_PREFIX + "$" + RandomString.make();
}