Skip to content

Commit cece4db

Browse files
committed
Switched to JUnit
1 parent 56dc995 commit cece4db

File tree

7 files changed

+30
-38
lines changed

7 files changed

+30
-38
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ lazy val root = (project in file("."))
1111
libraryDependencies ++= Seq(
1212
"org.postgresql" % "postgresql" % "42.5.4",
1313
"org.scala-lang" % "scala-library" % scalaVersion.value % Test,
14-
"org.scalameta" %% "munit" % "0.7.29" % Test,
14+
"com.github.sbt" % "junit-interface" % "0.13.2" % Test,
1515
"com.typesafe.slick" %% "slick" % "3.4.1" % Test,
1616
"org.slf4j" % "slf4j-nop" % "1.7.26" % Test,
1717
"org.springframework" % "spring-jdbc" % "5.3.27" % Test,

src/test/java/com/pgvector/Hibernate.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import org.hibernate.boot.MetadataSources;
99
import org.hibernate.Session;
1010
import org.hibernate.SessionFactory;
11+
import org.junit.Test;
1112

1213
public class Hibernate {
13-
public static void example() throws SQLException {
14+
@Test
15+
public void example() throws SQLException {
1416
// disable logging
1517
System.setProperty("org.jboss.logging.provider", "slf4j");
1618

src/test/java/com/pgvector/JDBCJava.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
import java.sql.*;
44
import com.pgvector.PGvector;
55
import org.postgresql.PGConnection;
6+
import org.junit.Test;
67

78
public class JDBCJava {
8-
public static void example(boolean read_binary) throws SQLException {
9+
@Test
10+
public void works() throws SQLException {
11+
example(false);
12+
}
13+
14+
@Test
15+
public void readBinary() throws SQLException {
16+
example(true);
17+
}
18+
19+
private void example(boolean read_binary) throws SQLException {
920
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/pgvector_java_test");
1021
if (read_binary) {
1122
conn.unwrap(PGConnection.class).setPrepareThreshold(-1);

src/test/java/com/pgvector/SpringJDBC.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import com.pgvector.PGvector;
77
import org.springframework.jdbc.core.JdbcTemplate;
88
import org.springframework.jdbc.datasource.DriverManagerDataSource;
9+
import org.junit.Test;
910

1011
public class SpringJDBC {
11-
public static void example() throws SQLException {
12+
@Test
13+
public void example() throws SQLException {
1214
DriverManagerDataSource dataSource = new DriverManagerDataSource();
1315
dataSource.setUrl("jdbc:postgresql://localhost:5432/pgvector_java_test");
1416

src/test/scala/com/pgvector/JDBCScala.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,30 @@ package com.pgvector
22

33
import java.sql.DriverManager
44
import com.pgvector.PGvector
5+
import org.junit.Test
56

6-
object JDBCScala {
7+
class JDBCScala {
8+
@Test
79
def example(): Unit = {
810
val conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/pgvector_java_test")
911

1012
val setupStmt = conn.createStatement()
1113
setupStmt.executeUpdate("CREATE EXTENSION IF NOT EXISTS vector")
12-
setupStmt.executeUpdate("DROP TABLE IF EXISTS jdbc_items")
14+
setupStmt.executeUpdate("DROP TABLE IF EXISTS jdbc_scala_items")
1315

1416
PGvector.addVectorType(conn)
1517

1618
val createStmt = conn.createStatement()
17-
createStmt.executeUpdate("CREATE TABLE jdbc_items (id bigserial PRIMARY KEY, embedding vector(3))")
19+
createStmt.executeUpdate("CREATE TABLE jdbc_scala_items (id bigserial PRIMARY KEY, embedding vector(3))")
1820

19-
val insertStmt = conn.prepareStatement("INSERT INTO jdbc_items (embedding) VALUES (?), (?), (?), (?)")
21+
val insertStmt = conn.prepareStatement("INSERT INTO jdbc_scala_items (embedding) VALUES (?), (?), (?), (?)")
2022
insertStmt.setObject(1, new PGvector(Array[Float](1, 1, 1)))
2123
insertStmt.setObject(2, new PGvector(Array[Float](2, 2, 2)))
2224
insertStmt.setObject(3, new PGvector(Array[Float](1, 1, 2)))
2325
insertStmt.setObject(4, new PGvector())
2426
insertStmt.executeUpdate()
2527

26-
val neighborStmt = conn.prepareStatement("SELECT * FROM jdbc_items ORDER BY embedding <-> ? LIMIT 5")
28+
val neighborStmt = conn.prepareStatement("SELECT * FROM jdbc_scala_items ORDER BY embedding <-> ? LIMIT 5")
2729
neighborStmt.setObject(1, new PGvector(Array[Float](1, 1, 1)))
2830
val rs = neighborStmt.executeQuery()
2931
while (rs.next()) {
@@ -32,7 +34,7 @@ object JDBCScala {
3234
}
3335

3436
val indexStmt = conn.createStatement()
35-
indexStmt.executeUpdate("CREATE INDEX jdbc_index ON jdbc_items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)")
37+
indexStmt.executeUpdate("CREATE INDEX jdbc_scala_index ON jdbc_scala_items USING ivfflat (embedding vector_l2_ops) WITH (lists = 100)")
3638

3739
conn.close()
3840
}

src/test/scala/com/pgvector/MainSpec.scala

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/test/scala/com/pgvector/Slick.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import scala.concurrent.duration._
55
import scala.concurrent.ExecutionContext.Implicits.global
66
import slick.jdbc.PostgresProfile.api._
77
import com.pgvector.PGvector
8+
import org.junit.Test
89

910
class Items(tag: Tag) extends Table[(String)](tag, "slick_items") {
1011
def embedding = column[String]("embedding", O.SqlType("vector(3)"))
1112
def * = (embedding)
1213
}
1314

14-
object Slick {
15+
class Slick {
16+
@Test
1517
def example(): Unit = {
1618
val db = Database.forURL("jdbc:postgresql://localhost:5432/pgvector_java_test", driver="org.postgresql.Driver")
1719

0 commit comments

Comments
 (0)