Skip to content

Commit fe472f1

Browse files
Test Db Application (#54)
1 parent c6d4f54 commit fe472f1

File tree

3 files changed

+196
-0
lines changed

3 files changed

+196
-0
lines changed

jdbc/spring-test-db/pom.xml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>tech.ydb.jdbc.examples</groupId>
5+
<artifactId>ydb-jdbc-examples</artifactId>
6+
<version>1.1.0-SNAPSHOT</version>
7+
</parent>
8+
9+
<artifactId>spring-test-db</artifactId>
10+
<name>Spring Data Test Db Example</name>
11+
<properties>
12+
<maven.compiler.release>17</maven.compiler.release>
13+
<kotlin.version>1.9.22</kotlin.version>
14+
<hibernate.ydb.dialect.version>1.4.0</hibernate.ydb.dialect.version>
15+
<spring.boot.version>3.2.1</spring.boot.version>
16+
</properties>
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter-data-jpa</artifactId>
21+
<version>${spring.boot.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework.data</groupId>
25+
<artifactId>spring-data-commons</artifactId>
26+
<version>${spring.boot.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.jetbrains.kotlin</groupId>
30+
<artifactId>kotlin-reflect</artifactId>
31+
<version>${kotlin.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.jetbrains.kotlin</groupId>
35+
<artifactId>kotlin-stdlib</artifactId>
36+
<version>${kotlin.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>tech.ydb.dialects</groupId>
40+
<artifactId>hibernate-ydb-dialect</artifactId>
41+
<version>${hibernate.ydb.dialect.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>tech.ydb.jdbc</groupId>
45+
<artifactId>ydb-jdbc-driver</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.github.javafaker</groupId>
49+
<artifactId>javafaker</artifactId>
50+
<version>1.0.2</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.jetbrains.kotlinx</groupId>
54+
<artifactId>kotlinx-coroutines-core</artifactId>
55+
<version>1.7.3</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.postgresql</groupId>
59+
<artifactId>postgresql</artifactId>
60+
<version>42.7.3</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.testcontainers</groupId>
64+
<artifactId>postgresql</artifactId>
65+
<version>1.19.1</version>
66+
<scope>test</scope>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-test</artifactId>
72+
<version>${spring.boot.version}</version>
73+
<scope>test</scope>
74+
</dependency>
75+
<dependency>
76+
<groupId>tech.ydb.test</groupId>
77+
<artifactId>ydb-junit5-support</artifactId>
78+
<scope>test</scope>
79+
</dependency>
80+
</dependencies>
81+
<build>
82+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
83+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
84+
<plugins>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-surefire-plugin</artifactId>
88+
<configuration>
89+
<environmentVariables>
90+
<TESTCONTAINERS_REUSE_ENABLE>true</TESTCONTAINERS_REUSE_ENABLE>
91+
</environmentVariables>
92+
</configuration>
93+
</plugin>
94+
<plugin>
95+
<groupId>org.springframework.boot</groupId>
96+
<artifactId>spring-boot-maven-plugin</artifactId>
97+
<version>${spring.boot.version}</version>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.jetbrains.kotlin</groupId>
101+
<artifactId>kotlin-maven-plugin</artifactId>
102+
<version>${kotlin.version}</version>
103+
<executions>
104+
<execution>
105+
<id>compile</id>
106+
<phase>compile</phase>
107+
<goals>
108+
<goal>compile</goal>
109+
</goals>
110+
</execution>
111+
<execution>
112+
<id>test-compile</id>
113+
<goals>
114+
<goal>test-compile</goal>
115+
</goals>
116+
</execution>
117+
</executions>
118+
<configuration>
119+
<jvmTarget>17</jvmTarget>
120+
<args>
121+
<arg>-Xjsr305=strict</arg>
122+
</args>
123+
<compilerPlugins>
124+
<plugin>spring</plugin>
125+
<plugin>jpa</plugin>
126+
</compilerPlugins>
127+
</configuration>
128+
<dependencies>
129+
<dependency>
130+
<groupId>org.jetbrains.kotlin</groupId>
131+
<artifactId>kotlin-maven-allopen</artifactId>
132+
<version>${kotlin.version}</version>
133+
</dependency>
134+
<dependency>
135+
<groupId>org.jetbrains.kotlin</groupId>
136+
<artifactId>kotlin-maven-noarg</artifactId>
137+
<version>${kotlin.version}</version>
138+
</dependency>
139+
</dependencies>
140+
</plugin>
141+
</plugins>
142+
</build>
143+
</project>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package tech.ydb.testdb
2+
3+
import jakarta.persistence.EntityManager
4+
import org.slf4j.LoggerFactory
5+
import org.springframework.beans.factory.annotation.Autowired
6+
import org.springframework.boot.CommandLineRunner
7+
import org.springframework.boot.autoconfigure.SpringBootApplication
8+
import org.springframework.boot.runApplication
9+
import java.time.Instant
10+
11+
/**
12+
* @author Kirill Kurdyukov
13+
*/
14+
@SpringBootApplication
15+
class TestDbApplication : CommandLineRunner {
16+
companion object {
17+
private val log = LoggerFactory.getLogger(TestDbApplication::class.java)
18+
}
19+
20+
@Autowired
21+
lateinit var entityManager: EntityManager
22+
23+
override fun run(vararg args: String?) {
24+
val testString = String(ByteArray(1024) { 'a'.code.toByte() })
25+
26+
var sink = 0
27+
val t0 = System.nanoTime()
28+
val end = t0 + 10_000_000_000L
29+
var count = 0
30+
while (System.nanoTime() < end) {
31+
sink += getFixedString(testString).length
32+
count++
33+
}
34+
val elapsed = System.nanoTime() - t0
35+
val avgMs = elapsed.toDouble() / count / 1_000_000.0
36+
val opsPerSec = count * 1e9 / elapsed
37+
log.info("avg={} ms/op, throughput={} ops/s", avgMs, opsPerSec)
38+
}
39+
40+
fun getFixedString(s: String): String {
41+
return entityManager.createNativeQuery("SELECT ?1")
42+
.setParameter(1, s)
43+
.singleResult.toString()
44+
}
45+
}
46+
47+
fun main(args: Array<String>) {
48+
runApplication<TestDbApplication>(*args)
49+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spring.jpa.properties.hibernate.dialect=tech.ydb.hibernate.dialect.YdbDialect
2+
3+
spring.datasource.driver-class-name=tech.ydb.jdbc.YdbDriver
4+
spring.datasource.url=jdbc:ydb:grpc://localhost:2136/local

0 commit comments

Comments
 (0)