More lambda expressions for integration tests
This commit is contained in:
parent
55f5fae630
commit
77699bafcc
@ -1567,18 +1567,15 @@ xxxxxx xxxxx xxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxx
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxx x
|
||||
xxxxxxxxx
|
||||
xxxxxx xx xxxxxxx xxxxxxx xx xxxxxxxxxxxxxxx xx xxxxxxxxxxxxx xxxxxxxxxxxxx xxxxxxxxxxx xxxxx xxxxxxx xxxxxxx xx xxxxx x
|
||||
xxxxxx xxx xxxxxxxxxxxxxxx xxxx x
|
||||
xxxxxxxxx
|
||||
xxxxxx x xxxxx xxxxxxx x
|
||||
xxxxxx xxxxxx xx x
|
||||
|
||||
xx xxxxx xxx xxxx xxxx xxx xxxx xxxx
|
||||
xx xxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxx x
|
||||
xxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx xxxxx
|
||||
x
|
||||
|
||||
xxxxxx xxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
|
||||
xx xxxxx xxx xxxx xxxx xxx xxxx xxxx
|
||||
xx xxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxx x
|
||||
xxxxxxxxxxxxxxxxxxxx
|
||||
xxxxxx xxxxx
|
||||
x
|
||||
|
||||
xxxxxx xxx xxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxx
|
||||
xx
|
||||
x
|
||||
xxx
|
||||
|
||||
@ -1517,21 +1517,11 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
@Override
|
||||
public <R extends Record, E> RecordMapper<R, E> provide(RecordType<R> rowType, Class<? extends E> type) {
|
||||
if (type == Integer.class) {
|
||||
return new RecordMapper<R, E>() {
|
||||
@Override
|
||||
public E map(R record) {
|
||||
return (E) record.getValue(TBook_ID());
|
||||
}
|
||||
};
|
||||
return record -> (E) record.getValue(TBook_ID());
|
||||
}
|
||||
|
||||
if (type == String.class && rowType.field(TBook_TITLE()) != null) {
|
||||
return new RecordMapper<R, E>() {
|
||||
@Override
|
||||
public E map(R record) {
|
||||
return (E) record.getValue(TBook_TITLE());
|
||||
}
|
||||
};
|
||||
return record -> (E) record.getValue(TBook_TITLE());
|
||||
}
|
||||
|
||||
throw new NoRecordMapperAvailableException();
|
||||
|
||||
@ -373,48 +373,42 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
final DSLContext create2 = create(create().configuration().derive(new DefaultConnectionProvider(connection2)));
|
||||
|
||||
final Vector<String> execOrder = new Vector<String>();
|
||||
final Thread t1 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sleep(2000);
|
||||
execOrder.add("t1-block");
|
||||
try {
|
||||
create1
|
||||
.select(TAuthor_ID())
|
||||
.from(TAuthor())
|
||||
.forUpdate()
|
||||
.fetch();
|
||||
}
|
||||
final Thread t1 = new Thread(() -> {
|
||||
sleep(2000);
|
||||
execOrder.add("t1-block");
|
||||
try {
|
||||
create1
|
||||
.select(TAuthor_ID())
|
||||
.from(TAuthor())
|
||||
.forUpdate()
|
||||
.fetch();
|
||||
}
|
||||
|
||||
// Some databases fail on locking, others lock for a while
|
||||
catch (DataAccessException ignore) {
|
||||
}
|
||||
finally {
|
||||
execOrder.add("t1-fail-or-t2-commit");
|
||||
}
|
||||
// Some databases fail on locking, others lock for a while
|
||||
catch (DataAccessException ignore) {
|
||||
}
|
||||
finally {
|
||||
execOrder.add("t1-fail-or-t2-commit");
|
||||
}
|
||||
});
|
||||
|
||||
final Thread t2 = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
execOrder.add("t2-exec");
|
||||
Result<A> result2 = create2
|
||||
.selectFrom(TAuthor())
|
||||
.forUpdate()
|
||||
.fetch();
|
||||
assertEquals(2, result2.size());
|
||||
final Thread t2 = new Thread(() -> {
|
||||
execOrder.add("t2-exec");
|
||||
Result<A> result2 = create2
|
||||
.selectFrom(TAuthor())
|
||||
.forUpdate()
|
||||
.fetch();
|
||||
assertEquals(2, result2.size());
|
||||
|
||||
execOrder.add("t2-signal");
|
||||
sleep(4000);
|
||||
execOrder.add("t1-fail-or-t2-commit");
|
||||
execOrder.add("t2-signal");
|
||||
sleep(4000);
|
||||
execOrder.add("t1-fail-or-t2-commit");
|
||||
|
||||
try {
|
||||
create2.configuration().connectionProvider().acquire().commit();
|
||||
create2.configuration().connectionProvider().acquire().close();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
try {
|
||||
create2.configuration().connectionProvider().acquire().commit();
|
||||
create2.configuration().connectionProvider().acquire().close();
|
||||
}
|
||||
catch (Exception e) {}
|
||||
});
|
||||
|
||||
// This is the test case:
|
||||
|
||||
@ -50,8 +50,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Date;
|
||||
@ -378,16 +376,12 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
Proxy.newProxyInstance(
|
||||
PreparedStatement.class.getClassLoader(),
|
||||
new Class[] { PreparedStatement.class },
|
||||
new InvocationHandler() {
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
if (method.getName().equals("close")) {
|
||||
closed++;
|
||||
}
|
||||
|
||||
return Reflect.on(delegate).call(method.getName(), args).get();
|
||||
(proxy, method, args) -> {
|
||||
if (method.getName().equals("close")) {
|
||||
closed++;
|
||||
}
|
||||
|
||||
return Reflect.on(delegate).call(method.getName(), args).get();
|
||||
});
|
||||
|
||||
if (!delegate.getClass().getName().toLowerCase().contains("proxy")) {
|
||||
@ -421,16 +415,12 @@ extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, UU, I, IPK, T7
|
||||
TBook(), TBook(), TBook(), TBook());
|
||||
|
||||
try {
|
||||
new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (InterruptedException ignore) {}
|
||||
select.cancel();
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
}
|
||||
catch (InterruptedException ignore) {}
|
||||
select.cancel();
|
||||
}).start();
|
||||
|
||||
// The fetch should never terminate, as the above thread should cancel it
|
||||
|
||||
@ -162,8 +162,6 @@ import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StopWatch;
|
||||
import org.jooq.tools.StringUtils;
|
||||
import org.jooq.tools.jdbc.MockConnection;
|
||||
import org.jooq.tools.jdbc.MockDataProvider;
|
||||
import org.jooq.tools.jdbc.MockExecuteContext;
|
||||
import org.jooq.tools.jdbc.MockResult;
|
||||
import org.jooq.tools.reflect.ReflectException;
|
||||
import org.jooq.types.UByte;
|
||||
@ -568,62 +566,58 @@ public abstract class jOOQAbstractTest<
|
||||
|
||||
// Reactivate this, to enable mock connections
|
||||
if (false)
|
||||
connection = new MockConnection(new MockDataProvider() {
|
||||
connection = new MockConnection(context -> {
|
||||
DSLContext executor = DSL.using(c, getDialect());
|
||||
|
||||
@Override
|
||||
public MockResult[] execute(MockExecuteContext context) throws SQLException {
|
||||
DSLContext executor = DSL.using(c, getDialect());
|
||||
if (context.batchSingle()) {
|
||||
Query query = executor.query(context.sql(), new Object[context.batchBindings()[0].length]);
|
||||
int[] result =
|
||||
executor.batch(query)
|
||||
.bind(context.batchBindings())
|
||||
.execute();
|
||||
|
||||
if (context.batchSingle()) {
|
||||
Query query = executor.query(context.sql(), new Object[context.batchBindings()[0].length]);
|
||||
int[] result =
|
||||
executor.batch(query)
|
||||
.bind(context.batchBindings())
|
||||
.execute();
|
||||
|
||||
MockResult[] r = new MockResult[result.length];
|
||||
for (int i = 0; i < r.length; i++) {
|
||||
r[i] = new MockResult(result[i], null);
|
||||
}
|
||||
|
||||
return r;
|
||||
MockResult[] r = new MockResult[result.length];
|
||||
for (int i = 0; i < r.length; i++) {
|
||||
r[i] = new MockResult(result[i], null);
|
||||
}
|
||||
else if (context.batchMultiple()) {
|
||||
List<Query> queries = new ArrayList<Query>();
|
||||
|
||||
for (String sql : context.batchSQL()) {
|
||||
queries.add(executor.query(sql));
|
||||
}
|
||||
return r;
|
||||
}
|
||||
else if (context.batchMultiple()) {
|
||||
List<Query> queries = new ArrayList<Query>();
|
||||
|
||||
int[] result =
|
||||
executor.batch(queries)
|
||||
.execute();
|
||||
|
||||
MockResult[] r = new MockResult[result.length];
|
||||
for (int i = 0; i < r.length; i++) {
|
||||
r[i] = new MockResult(result[i], null);
|
||||
}
|
||||
|
||||
return r;
|
||||
for (String sql : context.batchSQL()) {
|
||||
queries.add(executor.query(sql));
|
||||
}
|
||||
else if (context.sql().toLowerCase().matches("(?s:\\W*(select|with).*)")) {
|
||||
List<Result<Record>> result = executor.fetchMany(context.sql(), context.bindings());
|
||||
MockResult[] r = new MockResult[result.size()];
|
||||
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
r[i] = new MockResult(result.get(i).size(), result.get(i));
|
||||
}
|
||||
int[] result =
|
||||
executor.batch(queries)
|
||||
.execute();
|
||||
|
||||
return r;
|
||||
MockResult[] r = new MockResult[result.length];
|
||||
for (int i = 0; i < r.length; i++) {
|
||||
r[i] = new MockResult(result[i], null);
|
||||
}
|
||||
else {
|
||||
int result = executor.execute(context.sql(), context.bindings());
|
||||
|
||||
MockResult[] r = new MockResult[1];
|
||||
r[0] = new MockResult(result, null);
|
||||
return r;
|
||||
}
|
||||
else if (context.sql().toLowerCase().matches("(?s:\\W*(select|with).*)")) {
|
||||
List<Result<Record>> result = executor.fetchMany(context.sql(), context.bindings());
|
||||
MockResult[] r = new MockResult[result.size()];
|
||||
|
||||
return r;
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
r[i] = new MockResult(result.get(i).size(), result.get(i));
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
else {
|
||||
int result = executor.execute(context.sql(), context.bindings());
|
||||
|
||||
MockResult[] r = new MockResult[1];
|
||||
r[0] = new MockResult(result, null);
|
||||
|
||||
return r;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user