diff --git a/Sanity/basic-sanity/Test.java b/Sanity/basic-sanity/Test.java new file mode 100644 index 0000000..22b6207 --- /dev/null +++ b/Sanity/basic-sanity/Test.java @@ -0,0 +1,98 @@ +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Test.java of /CoreOS/postgresql-jdbc/Sanity/basic-sanity +// Description: Runs basic sanity - select, insert, update, delete +// Author: Lukas Zachar +// +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// +// Copyright (c) 2013 Red Hat, Inc. All rights reserved. +// +// This copyrighted material is made available to anyone wishing +// to use, modify, copy, or redistribute it subject to the terms +// and conditions of the GNU General Public License version 2. +// +// This program is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied +// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the Free +// Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +// Boston, MA 02110-1301, USA. +// +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.Statement; + +public class Test { + public static void main(String[] args) throws Exception { + String jdbs_connection = "jdbc:postgresql://127.0.0.1/mydbtest"; + String user = "dbuser"; + + ResultSet rs = null; + + System.out.println("Test:: Begin"); + try { + Connection connection = DriverManager.getConnection(jdbs_connection, user, null); + + Statement stmt = connection.createStatement(); + + if (stmt.execute("SELECT VERSION()")) { + rs = stmt.getResultSet(); + while (rs.next()) { + System.out.println("SELECT VERSION: " + rs.getString(1)); + } + } + + System.out.println("Test:: Create table"); + stmt.execute("CREATE TABLE Writers(Id SERIAL, Name VARCHAR(25))"); + stmt.execute("INSERT INTO Writers(Name) VALUES('Jack London')"); + stmt.execute("INSERT INTO Writers(Name) VALUES('Honore de Balzac')"); + stmt.execute("INSERT INTO Writers(Name) VALUES('Lion Feuchtwanger')"); + + System.out.println("Test:: Read newly created table"); + if (stmt.execute("SELECT * FROM Writers")) { + rs = stmt.getResultSet(); + while (rs.next()) { + int myId = rs.getInt("id"); + String myName = rs.getString("Name"); + System.out.println(myId + ": " + myName); + } + } + + System.out.println("Test:: Update row (2-> Maupasant)"); + if (stmt.executeUpdate("UPDATE Writers SET Name = 'Guy de Maupasant' WHERE Id = 2") != 1 ) { + System.out.println("Test:: update count was not 1"); + } + + System.out.println("Test:: Delete row (1-> London)"); + if (stmt.executeUpdate("DELETE FROM Writers WHERE Id = 1") != 1) { + System.out.println("Test:: delete count was not 1"); + } + + System.out.println("Test:: Read modified table"); + if (stmt.execute("SELECT * FROM Writers")) { + rs = stmt.getResultSet(); + while (rs.next()) { + int myId = rs.getInt("id"); + String myName = rs.getString("Name"); + System.out.println(myId + ": " + myName); + } + } + + System.out.println("Test:: Drop table"); + stmt.execute("DROP TABLE Writers"); + + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + System.out.println("Test:: End"); + } +} diff --git a/Sanity/basic-sanity/expected.out b/Sanity/basic-sanity/expected.out new file mode 100644 index 0000000..2fb649a --- /dev/null +++ b/Sanity/basic-sanity/expected.out @@ -0,0 +1,14 @@ +Test:: Begin +SELECT VERSION: #REMOVED# +Test:: Create table +Test:: Read newly created table +1: Jack London +2: Honore de Balzac +3: Lion Feuchtwanger +Test:: Update row (2-> Maupasant) +Test:: Delete row (1-> London) +Test:: Read modified table +3: Lion Feuchtwanger +2: Guy de Maupasant +Test:: Drop table +Test:: End diff --git a/Sanity/basic-sanity/main.fmf b/Sanity/basic-sanity/main.fmf new file mode 100644 index 0000000..aaf6068 --- /dev/null +++ b/Sanity/basic-sanity/main.fmf @@ -0,0 +1,18 @@ +summary: Runs basic sanity - select, insert, update, delete +description: | + Runs basic sanity - select, insert, update, delete +contact: Lukas Zachar +component: + - postgresql-jdbc +path: /Sanity/basic-sanity +framework: beakerlib +require: + - postgresql-jdbc + - postgresql-server + - postgresql +duration: 25m +tag: + - Tier1 + - DBconnectors1 + - DBconnectors2 +tier: '1' diff --git a/Sanity/basic-sanity/runtest.sh b/Sanity/basic-sanity/runtest.sh new file mode 100755 index 0000000..3b27d49 --- /dev/null +++ b/Sanity/basic-sanity/runtest.sh @@ -0,0 +1,75 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/postgresql-jdbc/Sanity/basic-sanity +# Description: Runs basic sanity - select, insert, update, delete +# Author: Lukas Zachar +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2013 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +REQUIRES="${REQUIRES:-postgresql-jdbc}" + +# Options for java test +CONNECTOR_JAR="${CONNECTOR_JAR:-/usr/share/java/postgresql-jdbc.jar}" + +JAVA="${JAVA:-java}" + +rlJournalStart + rlPhaseStartSetup + rlLog "$(readlink -f $(which $JAVA))" + rlLog "$(rpm -qf $CONNECTOR_JAR)" + rlAssertRpm --all + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "chmod 777 $TmpDir" 0 "fixing directory permissions" + rlRun "cp expected.out Test.java $TmpDir/." + rlRun "pushd $TmpDir" + + rlRun "su - postgres -c 'initdb --auth trust --auth-host trust -D /var/lib/pgsql/data'" + rlRun "mkdir /var/run/postgresql/" + rlRun "chown postgres /var/run/postgresql/" + rlRun "su - postgres -c 'pg_ctl -D /var/lib/pgsql/data -l logfile start'" + + rlRun "su postgres -c 'createuser -d dbuser'" + rlRun "su postgres -c 'createdb -O dbuser mydbtest'" + rlPhaseEnd + + rlPhaseStartTest + rlRun "$JAVA -Djdbc.drivers=org.postgresql.Driver -cp $CONNECTOR_JAR:. Test.java > output.log" + rlLog "$(grep 'SELECT VERSION' output.log)" + # version will change, so we should remove it + sed 's/SELECT VERSION:.*/SELECT VERSION: #REMOVED#/' output.log > removed_version.log + rlRun "diff removed_version.log expected.out" 0 "Got expected output" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "su - postgres -c 'pg_ctl stop'" + rlRun "rm -r /var/lib/pgsql/data" + rlRun "rm -r /var/run/postgresql/" + rlBundleLogs "outputs" *.log + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalEnd +rlJournalPrintText diff --git a/Sanity/upstream-testsuite/main.fmf b/Sanity/upstream-testsuite/main.fmf new file mode 100644 index 0000000..85f8e19 --- /dev/null +++ b/Sanity/upstream-testsuite/main.fmf @@ -0,0 +1,39 @@ +summary: Runs upstream testsuite +description: | + Runs the compiled tests using junit5 +enabled: true +link: + - relates: https://bugzilla.redhat.com/show_bug.cgi?id=2030646 +tag: + - Tier1 + - rhel-buildroot +tier: '1' +adjust: + - enabled: false + when: arch == s390x + continue: false + - enabled: false + when: distro < rhel-8 + continue: false + - enabled: false + when: distro > rhel-8 + continue: false + - enabled: false + when: distro == Fedora + continue: false +contact: Vaclav Danek +component: + - postgresql-jdbc +framework: beakerlib +require: + - postgresql + - postgresql-server + - postgresql-contrib + - postgresql-test-rpm-macros + - postgresql-jdbc + - postgresql-jdbc-tests + - junit5 + - classloader-leak-test-framework + - bcel + - apache-commons-lang3 +duration: 35m diff --git a/Sanity/upstream-testsuite/runtest.sh b/Sanity/upstream-testsuite/runtest.sh new file mode 100755 index 0000000..3cf1504 --- /dev/null +++ b/Sanity/upstream-testsuite/runtest.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /CoreOS/postgresql-jdbc/Sanity/upstream-testsuite +# Description: Runs upstream testsuite +# Author: Zuzana Miklankova +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2022 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing +# to use, modify, copy, or redistribute it subject to the terms +# and conditions of the GNU General Public License version 2. +# +# This program is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied +# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +REQUIRES="${REQUIRES:-postgresql-jdbc}" + +# Options for java test +CONNECTOR_JAR="${CONNECTOR_JAR:-/usr/share/java/postgresql-jdbc.jar}" + +JAVA="${JAVA:-java}" +JAVAC="${JAVAC:-javac}" + +rlJournalStart + rlPhaseStartSetup + rlLog "$(readlink -f $(which $JAVA))" + rlLog "$(readlink -f $(which $JAVAC))" + rlLog "$(rpm -qf $CONNECTOR_JAR)" + rlAssertRpm --all + rlRun "useradd mockbuild -m" + + rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory" + rlRun "chmod a+rwx $TmpDir" 0 "fixing directory permissions" + rlRun "pushd $TmpDir" + rlPhaseEnd + + rlPhaseStartTest + rlRun "su mockbuild $OLDPWD/usertest.sh" + rlPhaseEnd + + rlPhaseStartCleanup + rlBundleLogs *.log + rlRun "popd" + rlRun "rm -r $TmpDir" 0 "Removing tmp directory" + rlPhaseEnd +rlJournalEnd +rlJournalPrintText + diff --git a/Sanity/upstream-testsuite/usertest.sh b/Sanity/upstream-testsuite/usertest.sh new file mode 100755 index 0000000..9781ce6 --- /dev/null +++ b/Sanity/upstream-testsuite/usertest.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +set -ex + +exitcode=0 + +. /usr/share/postgresql-setup/postgresql_pkg_tests.sh + +PGTESTS_LOCALE=C.UTF-8 +echo "\ +server=localhost +port=$PGTESTS_PORT +database=test +username=test +password=test +privilegedUser=$PGTESTS_ADMIN +privilegedPassword=$PGTESTS_ADMINPASS +preparethreshold=5 +loglevel=0 +protocolVersion=0 +" > build.local.properties + +ln -s /usr/share/postgresql-jdbc-tests/build.properties . +cat build.properties +ln -s /usr/share/postgresql-jdbc-tests/ssltest.properties . +cat ssltest.properties +ln -s /usr/share/postgresql-jdbc-tests/certdir . + +JUNIT_CLASSPATH=/usr/share/java/postgresql-jdbc-tests.jar:/usr/share/java/postgresql-jdbc.jar: +JUNIT_CLASSPATH+=$(cat /usr/share/postgresql-jdbc-tests/classpath) +for jar in ${JUNIT_CLASSPATH//:/ }; do + if ! [ -f "${jar}" ]; then + echo "file ${jar} does not exist" + exitcode=1 + fi +done + +if [ $exitcode = 1 ]; then + exit $exitcode +fi + +pgtests_start + +# -Xmx1536m -- from pom.xml +# -ea -- one test uses assert statement, we need to enable it on runtime +# -Dbuild.properties.relative.path=. -- from pom.xml +# -Djunit.jupiter.extensions.autodetection.enabled=true -- from the debug build logs of a Maven build +ADDITIONAL_FLAGS="-Xmx1536m -ea -Dbuild.properties.relative.path=. -Djunit.jupiter.extensions.autodetection.enabled=true" \ +/usr/bin/junit-platform-console execute -cp "${JUNIT_CLASSPATH}" --select-package org.postgresql\ + --details=verbose --disable-ansi-colors\ + --exclude-classname org.postgresql.test.jdbc2.ConnectTimeoutTest\ +; + +pgtests_stop +pgtests_cleanup diff --git a/main.fmf b/main.fmf index a357a13..33ea642 100644 --- a/main.fmf +++ b/main.fmf @@ -1,3 +1,4 @@ -contact: Mikolaj Izdebski +contact: Marian Koncek framework: beakerlib test: ./runtest.sh +component: postgresql-jdbc