Java Code Examples for net.bytebuddy.dynamic.loading.ByteArrayClassLoader#ChildFirst
The following examples show how to use
net.bytebuddy.dynamic.loading.ByteArrayClassLoader#ChildFirst .
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: ContainerResourceMonitoringTracerTest.java From garmadon with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IOException, ClassNotFoundException { classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( Tracer.class, MethodTracer.class, ContainerResourceMonitoringTracer.class, ContainerResourceMonitoringTracer.VcoreUsageTracer.class, Class.forName(ContainerResourceMonitoringTracer.VcoreUsageTracer.class.getName() + "$SingletonHolder"), ContainersMonitorImpl.class, Class.forName(ContainersMonitorImpl.class.getName() + "$MonitoringThread"), ContainerMetrics.class, Class.forName(ContainerMetrics.class.getName() + "$1") ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 2
Source File: MapRedInputFormatTracerTest.java From garmadon with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IOException { eventHandler = mock(BiConsumer.class); argument = ArgumentCaptor.forClass(DataAccessEventProtos.PathEvent.class); MapReduceTracer.initEventHandler(eventHandler); inputSplit = mock(InputSplit.class); jobConf = mock(JobConf.class); reporter = mock(Reporter.class); when(jobConf.getJobName()).thenReturn("Application"); when(jobConf.getUser()).thenReturn("user"); classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( MapRedInputFormatTestClasses.OneLevelHierarchy.class, MapRedInputFormatTestClasses.AbstractInputFormat.class, MapRedInputFormatTestClasses.RealInputFormat.class, MapRedInputFormatTestClasses.Level1.class, MapRedInputFormatTestClasses.Level2CallingSuper.class, MapRedInputFormatTestClasses.Level3NotCallingSuper.class), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 3
Source File: MapRedOutputFormatTracerTest.java From garmadon with Apache License 2.0 | 6 votes |
@Before public void setUp() throws IOException { eventHandler = mock(BiConsumer.class); argument = ArgumentCaptor.forClass(DataAccessEventProtos.PathEvent.class); MapReduceTracer.initEventHandler(eventHandler); jobConf = mock(JobConf.class); when(jobConf.getJobName()) .thenReturn("Application"); when(jobConf.getUser()) .thenReturn("user"); classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( MapRedOutputFormatTestClasses.OneLevelHierarchy.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 4
Source File: RMappTracerTest.java From garmadon with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() throws IOException { classLoader = new ByteArrayClassLoader.ChildFirst(RMappTracerTest.class.getClassLoader(), ClassFileExtraction.of( Tracer.class, MethodTracer.class, RMAppTracer.class, RMAppTracer.RMContextImplThread.class, RMContextImplEventRunnable.class, RMContextImpl.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 5
Source File: RMContainerTracerTest.java From garmadon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( Tracer.class, MethodTracer.class, RMContainerTracer.class, RMContainerTracer.RMContainerImplTracer.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 6
Source File: MapReduceInputFormatTracerTest.java From garmadon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { eventHandler = mock(BiConsumer.class); argument = ArgumentCaptor.forClass(DataAccessEventProtos.PathEvent.class); MapReduceTracer.initEventHandler(eventHandler); inputSplit = mock(InputSplit.class); jobContext = mock(JobContext.class); taskAttemptContext = mock(TaskAttemptContext.class); conf = new Configuration(); conf.set("mapreduce.input.fileinputformat.inputdir", inputPath); when(jobContext.getConfiguration()) .thenReturn(conf); when(taskAttemptContext.getConfiguration()) .thenReturn(conf); when(jobContext.getJobName()) .thenReturn("Application"); when(jobContext.getUser()) .thenReturn("user"); when(taskAttemptContext.getJobName()) .thenReturn("Application"); when(taskAttemptContext.getUser()) .thenReturn("user"); JobID jobId = mock(JobID.class); when(jobId.toString()) .thenReturn("app_1"); when(jobContext.getJobID()) .thenReturn(jobId); when(taskAttemptContext.getJobID()) .thenReturn(jobId); classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( MapReduceInputFormatTestClasses.OneLevelHierarchy.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 7
Source File: MapReduceOutputFormatTracerTest.java From garmadon with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { eventHandler = mock(BiConsumer.class); argument = ArgumentCaptor.forClass(DataAccessEventProtos.PathEvent.class); MapReduceTracer.initEventHandler(eventHandler); taskAttemptContext = mock(TaskAttemptContext.class); conf = new Configuration(); conf.set("mapreduce.output.fileoutputformat.outputdir", outputPath); when(taskAttemptContext.getConfiguration()) .thenReturn(conf); when(taskAttemptContext.getJobName()) .thenReturn("Application"); when(taskAttemptContext.getUser()) .thenReturn("user"); JobID jobId = mock(JobID.class); when(jobId.toString()) .thenReturn("app_1"); when(taskAttemptContext.getJobID()) .thenReturn(jobId); classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileExtraction.of( MapReduceOutputFormatTestClasses.OneLevelHierarchy.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 8
Source File: PluginClassLoaderTracerTest.java From garmadon with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUpClass() throws IOException, ClassNotFoundException { classLoader = new ByteArrayClassLoader.ChildFirst(PluginClassLoaderTracerTest.class.getClassLoader(), ClassFileExtraction.of( Tracer.class, ConstructorTracer.class, PluginClassLoaderTracer.class, Class.forName("com.facebook.presto.server.PluginClassLoader") ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 9
Source File: AgentBuilderDefaultApplicationTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileLocator.ForClassLoader.readToNames(Foo.class, Bar.class, Qux.class, Baz.class, QuxBaz.class, SimpleType.class), ByteArrayClassLoader.PersistenceHandler.MANIFEST); }
Example 10
Source File: NexusTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testNexusAccessorNonActive() throws Exception { ClassLoader classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileLocator.ForClassLoader.readToNames(Nexus.class, NexusAccessor.class, NexusAccessor.Dispatcher.class, NexusAccessor.Dispatcher.CreationAction.class, NexusAccessor.Dispatcher.Available.class, NexusAccessor.Dispatcher.Unavailable.class), null, ByteArrayClassLoader.PersistenceHandler.MANIFEST, PackageDefinitionStrategy.NoOp.INSTANCE); Field duplicateInitializers = classLoader.loadClass(Nexus.class.getName()).getDeclaredField("TYPE_INITIALIZERS"); duplicateInitializers.setAccessible(true); assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); Field actualInitializers = Nexus.class.getDeclaredField("TYPE_INITIALIZERS"); actualInitializers.setAccessible(true); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(0)); Class<?> accessor = classLoader.loadClass(NexusAccessor.class.getName()); ClassLoader qux = mock(ClassLoader.class); when(loadedTypeInitializer.isAlive()).thenReturn(false); assertThat(accessor .getDeclaredMethod("register", String.class, ClassLoader.class, int.class, LoadedTypeInitializer.class) .invoke(accessor.getDeclaredConstructor().newInstance(), FOO, qux, BAR, loadedTypeInitializer), nullValue(Object.class)); try { assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(0)); } finally { Constructor<Nexus> constructor = Nexus.class.getDeclaredConstructor(String.class, ClassLoader.class, ReferenceQueue.class, int.class); constructor.setAccessible(true); Object value = ((Map<?, ?>) actualInitializers.get(null)).remove(constructor.newInstance(FOO, qux, null, BAR)); assertThat(value, nullValue()); } }
Example 11
Source File: NexusTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testNexusAccessorClassLoaderBoundary() throws Exception { ClassLoader classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileLocator.ForClassLoader.readToNames(Nexus.class, NexusAccessor.class, NexusAccessor.Dispatcher.class, NexusAccessor.Dispatcher.CreationAction.class, NexusAccessor.Dispatcher.Available.class, NexusAccessor.Dispatcher.Unavailable.class), null, ByteArrayClassLoader.PersistenceHandler.MANIFEST, PackageDefinitionStrategy.NoOp.INSTANCE); Field duplicateInitializers = classLoader.loadClass(Nexus.class.getName()).getDeclaredField("TYPE_INITIALIZERS"); duplicateInitializers.setAccessible(true); assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); Field actualInitializers = Nexus.class.getDeclaredField("TYPE_INITIALIZERS"); actualInitializers.setAccessible(true); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(0)); Class<?> accessor = classLoader.loadClass(NexusAccessor.class.getName()); ClassLoader qux = mock(ClassLoader.class); when(loadedTypeInitializer.isAlive()).thenReturn(true); assertThat(accessor .getDeclaredMethod("register", String.class, ClassLoader.class, int.class, LoadedTypeInitializer.class) .invoke(accessor.getDeclaredConstructor().newInstance(), FOO, qux, BAR, loadedTypeInitializer), nullValue(Object.class)); try { assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(1)); } finally { Constructor<Nexus> constructor = Nexus.class.getDeclaredConstructor(String.class, ClassLoader.class, ReferenceQueue.class, int.class); constructor.setAccessible(true); Object value = ((Map<?, ?>) actualInitializers.get(null)).remove(constructor.newInstance(FOO, qux, null, BAR)); assertThat(value, is((Object) loadedTypeInitializer)); } }
Example 12
Source File: NexusTest.java From byte-buddy with Apache License 2.0 | 5 votes |
@Test public void testNexusAccessorClassLoaderNoResource() throws Exception { ClassLoader classLoader = new ByteArrayClassLoader.ChildFirst(getClass().getClassLoader(), ClassFileLocator.ForClassLoader.readToNames(Nexus.class, NexusAccessor.class, NexusAccessor.Dispatcher.class, NexusAccessor.Dispatcher.CreationAction.class, NexusAccessor.Dispatcher.Available.class, NexusAccessor.Dispatcher.Unavailable.class), null, ByteArrayClassLoader.PersistenceHandler.LATENT, PackageDefinitionStrategy.NoOp.INSTANCE); Field duplicateInitializers = classLoader.loadClass(Nexus.class.getName()).getDeclaredField("TYPE_INITIALIZERS"); duplicateInitializers.setAccessible(true); assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); Field actualInitializers = Nexus.class.getDeclaredField("TYPE_INITIALIZERS"); actualInitializers.setAccessible(true); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(0)); Class<?> accessor = classLoader.loadClass(NexusAccessor.class.getName()); ClassLoader qux = mock(ClassLoader.class); when(loadedTypeInitializer.isAlive()).thenReturn(true); assertThat(accessor .getDeclaredMethod("register", String.class, ClassLoader.class, int.class, LoadedTypeInitializer.class) .invoke(accessor.getDeclaredConstructor().newInstance(), FOO, qux, BAR, loadedTypeInitializer), nullValue(Object.class)); try { assertThat(((Map<?, ?>) duplicateInitializers.get(null)).size(), is(0)); assertThat(((Map<?, ?>) actualInitializers.get(null)).size(), is(1)); } finally { Constructor<Nexus> constructor = Nexus.class.getDeclaredConstructor(String.class, ClassLoader.class, ReferenceQueue.class, int.class); constructor.setAccessible(true); Object value = ((Map<?, ?>) actualInitializers.get(null)).remove(constructor.newInstance(FOO, qux, null, BAR)); assertThat(value, is((Object) loadedTypeInitializer)); } }
Example 13
Source File: FileSystemTracerTest.java From garmadon with Apache License 2.0 | 4 votes |
@BeforeClass public static void setUpClass() throws IOException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, URISyntaxException, InstantiationException { classLoader = new ByteArrayClassLoader.ChildFirst(FileSystemTracerTest.class.getClassLoader(), ClassFileExtraction.of( Tracer.class, MethodTracer.class, FileSystemTracer.class, FileSystemTracer.WriteTracer.class, FileSystemTracer.ReadTracer.class, FileSystemTracer.AddBlockTracer.class, FileSystemTracer.ListStatusTracer.class, FileSystemTracer.GetContentSummaryTracer.class, FileSystemTracer.RenameTracer.class, FileSystemTracer.DeleteTracer.class, DFSClient.class, DFSClient.Conf.class, ClientContext.class, DistributedFileSystem.class, DomainSocketFactory.class, DFSInputStream.class, DFSOutputStream.class, HdfsDataInputStream.class, HdfsDataOutputStream.class, ClientNamenodeProtocolTranslatorPB.class, Class.forName("org.apache.hadoop.hdfs.DFSOpsCountStatistics"), Class.forName("org.apache.hadoop.hdfs.BlockReaderLocal"), Class.forName(DFSOutputStream.class.getName() + "$Packet"), Class.forName(DFSOutputStream.class.getName() + "$DataStreamer"), Class.forName(DFSOutputStream.class.getName() + "$DataStreamer$1"), Class.forName(DFSOutputStream.class.getName() + "$DataStreamer$2"), Class.forName(DFSOutputStream.class.getName() + "$DataStreamer$ResponseProcessor"), Class.forName(DistributedFileSystem.class.getName() + "$1"), Class.forName(DistributedFileSystem.class.getName() + "$4"), Class.forName(DistributedFileSystem.class.getName() + "$7"), Class.forName(DistributedFileSystem.class.getName() + "$13"), Class.forName(DistributedFileSystem.class.getName() + "$14"), Class.forName(DistributedFileSystem.class.getName() + "$16"), Class.forName(DistributedFileSystem.class.getName() + "$19"), Class.forName("org.apache.hadoop.hdfs.LeaseRenewer"), Class.forName("org.apache.hadoop.hdfs.LeaseRenewer$1"), Class.forName("org.apache.hadoop.hdfs.LeaseRenewer$Factory"), Class.forName("org.apache.hadoop.hdfs.LeaseRenewer$Factory$Key"), Class.forName("org.apache.hadoop.fs.Hdfs"), HdfsDataOutputStream.class ), ByteArrayClassLoader.PersistenceHandler.MANIFEST); argument = ArgumentCaptor.forClass(DataAccessEventProtos.FsEvent.class); eventHandler = mock(BiConsumer.class); ReflectionHelper.setField(null, classLoader.loadClass(FileSystemTracer.class.getName()), "eventHandler", eventHandler); ReflectionHelper.setField(conf, Configuration.class, "classLoader", classLoader); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); new FileSystemTracer.WriteTracer().installOnByteBuddyAgent(); new FileSystemTracer.ReadTracer().installOnByteBuddyAgent(); new FileSystemTracer.ListStatusTracer().installOnByteBuddyAgent(); new FileSystemTracer.GetContentSummaryTracer().installOnByteBuddyAgent(); new FileSystemTracer.DeleteTracer().installOnByteBuddyAgent(); new FileSystemTracer.RenameTracer().installOnByteBuddyAgent(); // MiniDfsCluster File baseDir = new File("./target/hdfs/test").getAbsoluteFile(); FileUtil.fullyDelete(baseDir); conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem"); conf.set(MiniDFSCluster.HDFS_MINIDFS_BASEDIR, baseDir.getAbsolutePath()); MiniDFSCluster.Builder builder = new MiniDFSCluster.Builder(conf) .simulatedCapacities(new long[] {10240000L}); hdfsCluster = builder.build(); hdfsURI = "hdfs://localhost:" + hdfsCluster.getNameNodePort(); initDFS(); }
Example 14
Source File: HelperClassManager.java From apm-agent-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static <T> Class<T> loadHelperClass(@Nullable ClassLoader targetClassLoader, String implementation, Map<String, byte[]> typeDefinitions) throws ClassNotFoundException { final ClassLoader helperCL = new ByteArrayClassLoader.ChildFirst(targetClassLoader, true, typeDefinitions); return (Class<T>) helperCL.loadClass(implementation); }