From 0688061f5cb2eed9b872ca2d648e9a72335cb55f Mon Sep 17 00:00:00 2001 From: rbygrave Date: Sun, 15 Aug 2021 15:17:19 +1200 Subject: [PATCH] Speed up TestUuidGenerator --- .../server/idgen/TestUuidGenerator.java | 47 ++++++------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/idgen/TestUuidGenerator.java b/ebean-core/src/test/java/io/ebeaninternal/server/idgen/TestUuidGenerator.java index 0f27c5a89..3623fdd73 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/idgen/TestUuidGenerator.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/idgen/TestUuidGenerator.java @@ -2,39 +2,32 @@ * Licensed Materials - Property of FOCONIS AG * (C) Copyright FOCONIS AG. */ - package io.ebeaninternal.server.idgen; - -import static org.assertj.core.api.Assertions.assertThat; +import io.ebean.config.dbplatform.PlatformIdGenerator; +import org.junit.Test; import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Test; - -import io.ebean.config.dbplatform.PlatformIdGenerator; - +import static org.assertj.core.api.Assertions.assertThat; /** * Run some simple tests for the UUID generator. * * @author Roland Praml, FOCONIS AG - * */ public class TestUuidGenerator { - -/** - * Worker to generate UUIDs - * - * @author Roland Praml, FOCONIS AG - * - */ + /** + * Worker to generate UUIDs + * + * @author Roland Praml, FOCONIS AG + */ public static class IdTest implements Runnable { - private final Map map; + private final Map map; private final PlatformIdGenerator idGen; private final int ids; private final AtomicBoolean failFlag; @@ -46,12 +39,6 @@ public class TestUuidGenerator { this.failFlag = failFlag; } - public IdTest(PlatformIdGenerator idGen, int ids) { - this.idGen = idGen; - this.ids = ids; - this.map = null; - this.failFlag = null; - } @Override public void run() { //System.out.println("Start " + Thread.currentThread()); @@ -70,7 +57,7 @@ public class TestUuidGenerator { */ @Test public void testUuidV1SingleThread() throws Exception { - testGenerator(1, 1_000_000, UuidV1IdGenerator.getInstance("ebean-test-uuid.state")); + testGenerator(1, 500_000, UuidV1IdGenerator.getInstance("ebean-test-uuid.state")); } /** @@ -78,7 +65,7 @@ public class TestUuidGenerator { */ @Test public void testUuidV1MultiThread() throws Exception { - testGenerator(10, 100_000, UuidV1IdGenerator.getInstance("ebean-test-uuid.state")); + testGenerator(10, 50_000, UuidV1IdGenerator.getInstance("ebean-test-uuid.state")); } /** @@ -86,7 +73,7 @@ public class TestUuidGenerator { */ @Test public void testUuidV1RndMultiThread() throws Exception { - testGenerator(10, 100_000, UuidV1RndIdGenerator.INSTANCE); + testGenerator(10, 50_000, UuidV1RndIdGenerator.INSTANCE); } /** @@ -94,7 +81,7 @@ public class TestUuidGenerator { */ @Test public void testUuidType1RndSingleThread() throws Exception { - testGenerator(1, 1_000_000, UuidV1RndIdGenerator.INSTANCE); + testGenerator(1, 500_000, UuidV1RndIdGenerator.INSTANCE); } /** @@ -102,7 +89,7 @@ public class TestUuidGenerator { */ @Test public void testUuidType4MultiThread() throws Exception { - testGenerator(10, 100_000, UuidV4IdGenerator.INSTANCE); + testGenerator(10, 50_000, UuidV4IdGenerator.INSTANCE); } /** @@ -110,12 +97,9 @@ public class TestUuidGenerator { */ @Test public void testUuidType4SingleThread() throws Exception { - testGenerator(1, 1_000_000, UuidV4IdGenerator.INSTANCE); + testGenerator(1, 500_000, UuidV4IdGenerator.INSTANCE); } - - - private void testGenerator(int threadCount, int count, PlatformIdGenerator generator) throws Exception { System.out.println("Printing 5 consecutive IDs of " + generator); for (int i = 0; i < 5; i++) { @@ -136,6 +120,5 @@ public class TestUuidGenerator { } assertThat(failFlag.get()).isFalse(); assertThat(map.size()).isEqualTo(threadCount * count); - } }