From 4e2ba22fc3de161da3bc854d5531a6b3a1489ea3 Mon Sep 17 00:00:00 2001 From: redkale Date: Sun, 13 Oct 2024 21:27:46 +0800 Subject: [PATCH] test --- pom.xml | 13 ++++ .../test/cached/CachedInstanceTest.java | 26 +------ .../test/convert/BenchmarkConvertTest.java | 67 +++++++++++++++++++ 3 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 src/test/java/org/redkale/test/convert/BenchmarkConvertTest.java diff --git a/pom.xml b/pom.xml index b8acc94aa..a77a452fa 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ 11 5.9.0 + 1.37 3.4.0 3.13.0 3.2.5 @@ -41,6 +42,18 @@ ${junit.version} test + + org.openjdk.jmh + jmh-core + ${jmh.version} + test + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + diff --git a/src/test/java/org/redkale/test/cached/CachedInstanceTest.java b/src/test/java/org/redkale/test/cached/CachedInstanceTest.java index c64bbfd56..4237c55f2 100644 --- a/src/test/java/org/redkale/test/cached/CachedInstanceTest.java +++ b/src/test/java/org/redkale/test/cached/CachedInstanceTest.java @@ -49,7 +49,7 @@ public class CachedInstanceTest { classLoader = RedkaleClassLoader.currentClassLoader(); CacheMemorySource remoteSource = new CacheMemorySource("cache-remote"); remoteSource.init(null); - + resourceFactory = ResourceFactory.create(); resourceFactory.register(new Environment()); manager = CachedManagerService.create(remoteSource); @@ -65,7 +65,6 @@ public class CachedInstanceTest { @Test public void run1() throws Exception { - RedkaleClassLoader classLoader = RedkaleClassLoader.currentClassLoader(); Class instanceClass = CachedInstance.class; CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, instanceClass); CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, instanceClass); @@ -103,7 +102,6 @@ public class CachedInstanceTest { @Test public void run2() throws Exception { - ClassLoader parent = Thread.currentThread().getContextClassLoader(); Class serviceClass = CachedInstance.class; CachedAsmMethodBoost boost = new CachedAsmMethodBoost(false, serviceClass); CachedAsmMethodBoost boost2 = new CachedAsmMethodBoost(false, serviceClass); @@ -112,28 +110,10 @@ public class CachedInstanceTest { SncpClient client = new SncpClient( "", iGroup, "0", new InetSocketAddress("127.0.0.1", 8080), new ClientAddress(), "TCP", 1, 16); CachedInstance instance = Sncp.createLocalService( - new RedkaleClassLoader(parent), - "", - serviceClass, - boost, - resourceFactory, - grous, - client, - null, - null, - null); + classLoader, "c", serviceClass, boost, resourceFactory, grous, client, null, null, null); resourceFactory.inject(instance); CachedInstance instance2 = Sncp.createLocalService( - new RedkaleClassLoader(parent), - "", - serviceClass, - boost2, - resourceFactory2, - grous, - client, - null, - null, - null); + classLoader, "d", serviceClass, boost2, resourceFactory2, grous, client, null, null, null); resourceFactory2.inject(instance2); int threads = Runtime.getRuntime().availableProcessors() * 10; diff --git a/src/test/java/org/redkale/test/convert/BenchmarkConvertTest.java b/src/test/java/org/redkale/test/convert/BenchmarkConvertTest.java new file mode 100644 index 000000000..0c454989f --- /dev/null +++ b/src/test/java/org/redkale/test/convert/BenchmarkConvertTest.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016-2116 Redkale + * All rights reserved. + */ +package org.redkale.test.convert; + +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.redkale.convert.json.JsonConvert; +import org.redkale.convert.pb.ProtobufConvert; + +/** + * + * @author zhangjx + */ +@State(Scope.Thread) +public class BenchmarkConvertTest { + + private SimpleEntity entry; + + @Setup + public void setup() { + entry = SimpleEntity.create(); + } + + @TearDown + public void tearDown() { + entry = null; + } + + @Benchmark + public void testA_Json() { + JsonConvert.root().convertTo(SimpleEntity.class, entry); + } + + @Benchmark + public void testB_Protobuf() { + ProtobufConvert.root().convertTo(SimpleEntity.class, entry); + } + +// @Test +// public void testBenchmark() throws Exception { +// Options options = new OptionsBuilder() +// .include(BenchmarkConvertTest.class.getSimpleName()) +// .forks(1) +// .threads(1) +// .warmupIterations(1) +// .measurementIterations(1) +// .mode(Mode.Throughput) +// .build(); +// new Runner(options).run(); +// } + + public static void main(String[] args) throws Exception { + Options options = new OptionsBuilder() + .include(BenchmarkConvertTest.class.getSimpleName()) + .forks(1) + .threads(1) + .warmupIterations(1) + .measurementIterations(1) + .mode(Mode.Throughput) + .build(); + new Runner(options).run(); + } +}