mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.metric.MetricFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BasicProfileLocationTest {
|
||||
|
||||
@Test
|
||||
public void obtain() {
|
||||
|
||||
DProfileLocation loc = new DTimedProfileLocation(12, "foo", MetricFactory.get().createTimedMetric("junk"));
|
||||
|
||||
assertThat(loc.obtain()).isTrue();
|
||||
assertThat(loc.fullLocation()).endsWith(":12)");
|
||||
if (System.getProperty("java.version").startsWith("1.8")) {
|
||||
assertThat(loc.location()).isEqualTo("sun.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
} else {
|
||||
assertThat(loc.location()).isEqualTo("java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0");
|
||||
}
|
||||
assertThat(loc.label()).isEqualTo("NativeMethodAccessorImpl.invoke0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_trimPackage() {
|
||||
|
||||
BasicProfileLocation loc = new BasicProfileLocation("com.foo.Bar.all");
|
||||
assertThat(loc.obtain()).isFalse();
|
||||
assertThat(loc.fullLocation()).isEqualTo("com.foo.Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("com.foo.Bar.all");
|
||||
assertThat(loc.label()).isEqualTo("Bar.all");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic_trimSinglePackage() {
|
||||
|
||||
BasicProfileLocation loc = new BasicProfileLocation("foo.Bar.all");
|
||||
assertThat(loc.obtain()).isFalse();
|
||||
assertThat(loc.fullLocation()).isEqualTo("foo.Bar.all");
|
||||
assertThat(loc.location()).isEqualTo("foo.Bar.all");
|
||||
assertThat(loc.label()).isEqualTo("Bar.all");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DTimedMetricMapTest {
|
||||
|
||||
@Test
|
||||
public void addSinceNanos() throws InterruptedException {
|
||||
|
||||
DTimedMetricMap metricMap = new DTimedMetricMap("addSinceNanos");
|
||||
|
||||
long nanos = System.nanoTime();
|
||||
Thread.sleep(10);
|
||||
|
||||
metricMap.addSinceNanos("some", nanos);
|
||||
|
||||
BasicMetricVisitor visitor = new BasicMetricVisitor();
|
||||
metricMap.visit(visitor);
|
||||
|
||||
MetaTimedMetric timedMetric = visitor.timedMetrics().get(0);
|
||||
assertThat(timedMetric.count()).isEqualTo(1);
|
||||
assertThat(timedMetric.total()).isGreaterThan(10);
|
||||
|
||||
metricMap.addSinceNanos("some", nanos);
|
||||
|
||||
visitor = new BasicMetricVisitor();
|
||||
metricMap.visit(visitor);
|
||||
|
||||
timedMetric = visitor.timedMetrics().get(0);
|
||||
assertThat(timedMetric.count()).isEqualTo(1);
|
||||
assertThat(timedMetric.total()).isGreaterThan(10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class DTimedMetricTest {
|
||||
|
||||
@Test
|
||||
public void addSinceNanos() throws InterruptedException {
|
||||
|
||||
DTimedMetric metric = new DTimedMetric("addSinceNanos");
|
||||
|
||||
long start = System.nanoTime();
|
||||
Thread.sleep(10);
|
||||
|
||||
metric.addSinceNanos(start);
|
||||
|
||||
DTimeMetricStats stats = metric.collect(true);
|
||||
assertThat(stats.count()).isEqualTo(1);
|
||||
assertThat(stats.total()).isGreaterThan(10);
|
||||
assertThat(stats.max()).isEqualTo(stats.total());
|
||||
|
||||
metric.addSinceNanos(start);
|
||||
|
||||
stats = metric.collect(true);
|
||||
assertThat(stats.count()).isEqualTo(1);
|
||||
assertThat(stats.total()).isGreaterThan(10);
|
||||
assertThat(stats.max()).isEqualTo(stats.total());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addBatchSince() throws InterruptedException {
|
||||
|
||||
DTimedMetric metric = new DTimedMetric("addSinceNanos");
|
||||
|
||||
long start = System.nanoTime();
|
||||
Thread.sleep(10);
|
||||
|
||||
metric.addBatchSince(start, 5);
|
||||
|
||||
DTimeMetricStats stats = metric.collect(true);
|
||||
assertThat(stats.count()).isEqualTo(5);
|
||||
assertThat(stats.total()).isGreaterThan(10000);
|
||||
assertThat(stats.max()).isEqualTo(stats.total() / 5);
|
||||
assertThat(stats.max()).isGreaterThan(10000 / 5);
|
||||
|
||||
metric.addBatchSince(start, 2);
|
||||
|
||||
stats = metric.collect(true);
|
||||
assertThat(stats.count()).isEqualTo(2);
|
||||
assertThat(stats.total()).isGreaterThan(10000);
|
||||
assertThat(stats.max()).isEqualTo(stats.total() / 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebean.meta.SortMetric;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class SortMetricTest {
|
||||
|
||||
private Comparator<MetaTimedMetric> sortMetric = SortMetric.NAME;
|
||||
|
||||
@Test
|
||||
public void compare_list() {
|
||||
|
||||
List<DTimeMetricStats> list = new ArrayList<>();
|
||||
list.add(create("d"));
|
||||
list.add(create("b"));
|
||||
list.add(create("c"));
|
||||
list.add(create(null));
|
||||
list.add(create("a"));
|
||||
list.sort(sortMetric);
|
||||
|
||||
String names = list.stream().map(DTimeMetricStats::name).collect(Collectors.joining());
|
||||
|
||||
assertEquals("nullabcd", names);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare_when_same() {
|
||||
|
||||
assertEquals(0, sortMetric.compare(create("foo"), create("foo")));
|
||||
assertEquals(0, sortMetric.compare(create(null), create(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare_when_less() {
|
||||
|
||||
assertEquals(-1, sortMetric.compare(create("a"), create("b")));
|
||||
assertEquals(-1, sortMetric.compare(create("foo"), create("goo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare_when_more() {
|
||||
|
||||
assertEquals(1, sortMetric.compare(create("b"), create("a")));
|
||||
assertEquals(1, sortMetric.compare(create("goo"), create("foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compare_when_nulls() {
|
||||
|
||||
assertEquals(0, sortMetric.compare(create(null), create(null)));
|
||||
assertEquals(1, sortMetric.compare(create("foo"), create(null)));
|
||||
assertEquals(-1, sortMetric.compare(create(null), create("foo")));
|
||||
}
|
||||
|
||||
private DTimeMetricStats create(String name) {
|
||||
return new DTimeMetricStats(name, false, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.ebeaninternal.server.profile;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class UtilLocationTest {
|
||||
|
||||
@Test
|
||||
public void label() {
|
||||
assertThat(UtilLocation.label("foo")).isEqualTo("foo");
|
||||
assertThat(UtilLocation.label("ProfileLocationTest$Other.<init>")).isEqualTo("ProfileLocationTest$Other.init");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loc() {
|
||||
assertThat(UtilLocation.loc("org.foo.MyFoo.doIt(MyFoo.java:12)")).isEqualTo("org.foo.MyFoo.doIt");
|
||||
assertThat(UtilLocation.label("org.foo.MyFoo.doIt")).isEqualTo("MyFoo.doIt");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user