[#371] Add integration tests for concurrent use of jOOQ
This commit is contained in:
parent
b07c403ea4
commit
65cf172dfe
115
jOOQ-test/src/org/jooq/test/_/testcases/ThreadSafetyTests.java
Normal file
115
jOOQ-test/src/org/jooq/test/_/testcases/ThreadSafetyTests.java
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Copyright (c) 2009-2012, Lukas Eder, lukas.eder@gmail.com
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed to you under the Apache License, Version 2.0
|
||||
* (the "License"); You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* . Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* . Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* . Neither the name "jOOQ" nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.jooq.test._.testcases;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import org.jooq.TableRecord;
|
||||
import org.jooq.UpdatableRecord;
|
||||
import org.jooq.test.BaseTest;
|
||||
import org.jooq.test.jOOQAbstractTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ThreadSafetyTests<
|
||||
A extends UpdatableRecord<A>,
|
||||
AP,
|
||||
B extends UpdatableRecord<B>,
|
||||
S extends UpdatableRecord<S>,
|
||||
B2S extends UpdatableRecord<B2S>,
|
||||
BS extends UpdatableRecord<BS>,
|
||||
L extends TableRecord<L>,
|
||||
X extends TableRecord<X>,
|
||||
DATE extends UpdatableRecord<DATE>,
|
||||
BOOL extends UpdatableRecord<BOOL>,
|
||||
D extends UpdatableRecord<D>,
|
||||
T extends UpdatableRecord<T>,
|
||||
U extends TableRecord<U>,
|
||||
I extends TableRecord<I>,
|
||||
IPK extends UpdatableRecord<IPK>,
|
||||
T658 extends TableRecord<T658>,
|
||||
T725 extends UpdatableRecord<T725>,
|
||||
T639 extends UpdatableRecord<T639>,
|
||||
T785 extends TableRecord<T785>>
|
||||
extends BaseTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658, T725, T639, T785> {
|
||||
|
||||
public ThreadSafetyTests(jOOQAbstractTest<A, AP, B, S, B2S, BS, L, X, DATE, BOOL, D, T, U, I, IPK, T658, T725, T639, T785> delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentExecution() throws Exception {
|
||||
// This test is an adapted version of a test case contributed by
|
||||
// Sergey Epik for [#1543]
|
||||
|
||||
Object lock = new Object();
|
||||
for (int i = 0; i < 64; i++) {
|
||||
new Thread(new RunnableTest(lock)).start();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
private class RunnableTest implements Runnable {
|
||||
private Object lock;
|
||||
|
||||
private RunnableTest(Object lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
synchronized (lock) {
|
||||
lock.wait();
|
||||
}
|
||||
|
||||
// [#371] In this case, all factories share the same connection
|
||||
// hence, they're probably
|
||||
assertEquals(4, (int) create().selectCount().from(TBook()).fetchOne(0, Integer.class));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -112,6 +112,7 @@ import org.jooq.test._.testcases.RenderAndBindTests;
|
||||
import org.jooq.test._.testcases.RoutineAndUDTTests;
|
||||
import org.jooq.test._.testcases.SchemaAndMappingTests;
|
||||
import org.jooq.test._.testcases.SelectTests;
|
||||
import org.jooq.test._.testcases.ThreadSafetyTests;
|
||||
import org.jooq.tools.JooqLogger;
|
||||
import org.jooq.tools.StopWatch;
|
||||
import org.jooq.tools.StringUtils;
|
||||
@ -1043,6 +1044,11 @@ public abstract class jOOQAbstractTest<
|
||||
new FetchTests(this).testFetchLater();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentExecution() throws Exception {
|
||||
new ThreadSafetyTests(this).testConcurrentExecution();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGrouping() throws Exception {
|
||||
new GroupByTests(this).testGrouping();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user