Created
August 24, 2020 17:57
-
-
Save marcelo-ochoa/7a146d8e216cf8e21e2fdba2518e5427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dom.benchmarking.swingbench.testcollection; | |
import com.dom.benchmarking.swingbench.kernel.DatabaseTransaction; | |
import com.dom.benchmarking.swingbench.kernel.SwingBenchException; | |
import com.dom.benchmarking.swingbench.kernel.SwingBenchTask; | |
import java.sql.Connection; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.util.Map; | |
import java.util.concurrent.atomic.AtomicInteger; | |
import java.util.concurrent.locks.Condition; | |
import java.util.concurrent.locks.Lock; | |
import java.util.concurrent.locks.ReentrantLock; | |
public abstract class StressTest extends DatabaseTransaction { | |
private static boolean initRunning = false; | |
private static boolean initCompleted = false; | |
private static Lock lock = new ReentrantLock(); | |
private static Condition initFinished = lock.newCondition(); | |
private static AtomicInteger sequence = new AtomicInteger(1); | |
public StressTest() { | |
} | |
public void init(Map parameters) throws SwingBenchException { | |
try { | |
lock.lock(); //No real need to use explicit locking, I simply prefer it | |
while (initRunning) { | |
initFinished.await(); | |
} | |
if (!initRunning && !initCompleted) { | |
initRunning = true; | |
Connection connection = (Connection) parameters.get(SwingBenchTask.JDBC_CONNECTION); | |
Statement st = connection.createStatement(); | |
try { | |
st.execute("drop table TESTCOLLECTION"); | |
} catch (SQLException ex) { // ignore the exception | |
} | |
st.execute( | |
"CREATE TABLE TESTCOLLECTION\n" + | |
"(ID VARCHAR2(255 BYTE),\n" + | |
" CREATED_ON TIMESTAMP(6),\n" + | |
" LAST_MODIFIED TIMESTAMP(6),\n" + | |
" VERSION VARCHAR2(255 BYTE),\n" + | |
" JSON_DOCUMENT VARCHAR2(4000),\n" + | |
" CHECK (JSON_DOCUMENT is json) ENABLE,\n" + | |
" PRIMARY KEY (ID)\n" + | |
") segment creation immediate memoptimize for write PARALLEL 4"); | |
st.execute("ALTER TABLE TESTCOLLECTION MODIFY(ID NOT NULL ENABLE)"); | |
st.execute("ALTER TABLE TESTCOLLECTION MODIFY(CREATED_ON NOT NULL ENABLE)"); | |
st.execute("ALTER TABLE TESTCOLLECTION MODIFY(LAST_MODIFIED NOT NULL ENABLE)"); | |
st.execute("ALTER TABLE TESTCOLLECTION MODIFY(VERSION NOT NULL ENABLE)"); | |
initRunning = false; | |
initCompleted = true; | |
initFinished.signalAll(); | |
} | |
lock.unlock(); | |
} catch (InterruptedException e) { | |
} catch (SQLException se) { | |
SwingBenchException sbe = new SwingBenchException("Couldn't initialise the benchmark : " + se.getMessage()); | |
sbe.setSeverity(SwingBenchException.UNRECOVERABLEERROR); | |
throw sbe; | |
} | |
} | |
protected int getSequence() { | |
return sequence.getAndIncrement(); | |
} | |
protected int getCurrentSequence() { | |
return sequence.get(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment