Import tests

This commit is contained in:
Marian Koncek 2025-03-06 20:54:43 +01:00
commit 7e9050edf5
9 changed files with 375 additions and 1 deletions

View file

@ -0,0 +1,44 @@
// https://fedoraproject.org/wiki/MariaDB_JDBC_connector
import java.sql.*;
public class Test {
public static void main(String[] args) throws Exception {
// create our mysql database connection
String socketFile = "/var/lib/mysql/mysql.sock";
if (args.length == 1) {
socketFile = args[0];
}
String host = "localhost";
// use clearly different port to be sure we connect over socket
String port = "55556";
String dbname = "information_schema";
String url = "jdbc:mariadb://" + host + ":" + port + "/" + dbname + "?localSocket=" + socketFile;
String username = "root";
String password = "";
Connection conn = DriverManager.getConnection(url, username, password);
// our SQL SELECT query.
// if you only need a few columns, specify them by name instead of using "*"
String query = "SELECT * FROM ENGINES";
// create the java statement
Statement st = conn.createStatement();
// execute the query, and get a java resultset
ResultSet rs = st.executeQuery(query);
// iterate through the java resultset
while (rs.next()) {
String engine = rs.getString("ENGINE");
String support = rs.getString("SUPPORT");
String comment = rs.getString("COMMENT");
String transactions = rs.getString("TRANSACTIONS");
String xa = rs.getString("XA");
String savepoints = rs.getString("SAVEPOINTS");
// print the results
System.out.format("%s, %s, %s, %s, %s, %s\n", engine, support, comment, transactions, xa, savepoints);
}
st.close();
}
}

View file

@ -0,0 +1,15 @@
summary: example connector usage with connection over socket
description: |
example connector usage with connection over socket
contact: Jakub Heger <jheger@redhat.com>
component: []
require:
- mariadb-java-client
- mariadb-server
- jna
- util-linux
duration: 5m
enabled: true
link:
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=1683112
- relates: https://bugzilla.redhat.com/show_bug.cgi?id=1697372

View file

@ -0,0 +1,65 @@
#!/bin/bash
# vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# runtest.sh of /CoreOS/mariadb-java-client/Sanity/JDBC-connector-example-socket
# Description: example connector usage with connection over socket
# Author: Jakub Janco <jjanco@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Copyright (c) 2019 Red Hat, Inc.
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 2 of
# the License, or (at your option) any later version.
#
# 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, see http://www.gnu.org/licenses/.
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="mariadb-java-client"
TestDir=$PWD
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlAssertRpm jna
rlAssertRpm mariadb-server
rlLogInfo "$(rpm -q --whatprovides java-devel)"
rlRun "TmpDir=\$(mktemp -d)" 0 "Creating tmp directory"
rlRun "cp Test.java $TmpDir/."
rlRun "pushd $TmpDir"
rlRun "mariadb-install-db --user=mysql --datadir=/var/lib/mysql"
rlRun "su -s /bin/bash mysql -c \"mariadbd --verbose --general-log=1 &\""
# wait until the server is ready
rlRun "tail -f /var/log/mariadb/mariadb.log | grep -q 'mariadbd: ready for connections.'"
rlAssertExists "/var/lib/mysql/mysql.sock"
rlPhaseEnd
rlPhaseStartTest
rlRun "java -Djdbc.drivers=org.mariadb.jdbc.Driver -cp /usr/lib/java/mariadb-java-client.jar:/usr/lib/java/jna.jar:. Test.java > output.log"
rlAssertGrep "PERFORMANCE_SCHEMA" "output.log"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "killall mariadbd"
rlRun "rm -r /var/lib/mysql /var/log/mariadb/mariadb.log"
rlRun "popd"
rlRun "rm -r $TmpDir" 0 "Removing tmp directory"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd