mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Speed up TestUuidGenerator
This commit is contained in:
1 parent
82c12b1565
commit
0688061f5c
1 file changed
+15
-32
@@ -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<UUID, UUID> map;
|
||||
private final Map<UUID, UUID> 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);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user