Split project into sub-projects
This commit is contained in:
25
dbt-test/build.gradle
Normal file
25
dbt-test/build.gradle
Normal file
@@ -0,0 +1,25 @@
|
||||
apply plugin: 'org.flywaydb.flyway'
|
||||
|
||||
dependencies {
|
||||
testCompile project(':dbt-core')
|
||||
testRuntime project(':dbt-core')
|
||||
|
||||
testCompile ratpack.dependency('h2')
|
||||
|
||||
testRuntime ratpack.dependency('jdbc-tx')
|
||||
testRuntime ratpack.dependency('session')
|
||||
|
||||
testRuntime 'org.flywaydb:flyway-core:5.0.7'
|
||||
testRuntime 'org.slf4j:slf4j-simple:1.7.25'
|
||||
|
||||
testCompile ratpack.dependency('test')
|
||||
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
|
||||
testCompile 'cglib:cglib:2.2.2'
|
||||
testCompile 'org.objenesis:objenesis:2.1'
|
||||
}
|
||||
|
||||
flyway {
|
||||
url = 'jdbc:h2:mem:dbtdb'
|
||||
user = 'SA'
|
||||
}
|
||||
run.dependsOn(flywayMigrate)
|
||||
40
dbt-test/src/ratpack/Ratpack.groovy
Normal file
40
dbt-test/src/ratpack/Ratpack.groovy
Normal file
@@ -0,0 +1,40 @@
|
||||
import com.devsoap.dbt.DBTModule
|
||||
import com.devsoap.dbt.config.DBTConfig
|
||||
import org.flywaydb.core.Flyway
|
||||
import org.h2.jdbcx.JdbcDataSource
|
||||
import ratpack.service.Service
|
||||
import ratpack.service.StartEvent
|
||||
import ratpack.session.SessionModule
|
||||
|
||||
import javax.sql.DataSource
|
||||
|
||||
import static ratpack.groovy.Groovy.ratpack
|
||||
|
||||
ratpack {
|
||||
|
||||
serverConfig {
|
||||
sysProps()
|
||||
require('/dbt', DBTConfig)
|
||||
}
|
||||
|
||||
bindings {
|
||||
|
||||
module SessionModule
|
||||
|
||||
module (DBTModule) {
|
||||
it.ledger.remoteUrl = 'http://localhost:8888/ledger'
|
||||
it.executor.remoteUrl = 'http://localhost:8888/executor'
|
||||
}
|
||||
|
||||
bindInstance(DataSource, new JdbcDataSource(url: 'jdbc:h2:mem:dbtdb;DB_CLOSE_DELAY=-1', user: ''))
|
||||
bind DatabaseService
|
||||
}
|
||||
}
|
||||
|
||||
class DatabaseService implements Service {
|
||||
|
||||
@Override
|
||||
void onStart(StartEvent event){
|
||||
new Flyway(dataSource: event.registry.get(DataSource)).migrate()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.devsoap.dbt
|
||||
|
||||
import ratpack.groovy.test.GroovyRatpackMainApplicationUnderTest
|
||||
import ratpack.impose.Impositions
|
||||
import ratpack.impose.ServerConfigImposition
|
||||
import ratpack.server.RatpackServer
|
||||
|
||||
class CustomPortMainApplicationUnderTest extends GroovyRatpackMainApplicationUnderTest {
|
||||
|
||||
private final int port
|
||||
|
||||
CustomPortMainApplicationUnderTest(int port) {
|
||||
this.port = port
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Impositions createImpositions() throws Exception {
|
||||
Impositions.of {
|
||||
it.add(ServerConfigImposition.of {
|
||||
it.port(port)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RatpackServer createServer() throws Exception {
|
||||
System.setProperty('ratpack.dbt.ledger.remoteUrl', "http://localhost:$port/ledger")
|
||||
System.setProperty('ratpack.dbt.executor.remoteUrl', "http://localhost:$port/executor")
|
||||
return super.createServer()
|
||||
}
|
||||
}
|
||||
35
dbt-test/src/test/groovy/com/devsoap/dbt/ExecutorSpec.groovy
Normal file
35
dbt-test/src/test/groovy/com/devsoap/dbt/ExecutorSpec.groovy
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.devsoap.dbt
|
||||
|
||||
import com.devsoap.dbt.data.BlockTransaction
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import spock.lang.AutoCleanup
|
||||
import spock.lang.Specification
|
||||
|
||||
class ExecutorSpec extends Specification {
|
||||
|
||||
def mapper = new ObjectMapper()
|
||||
|
||||
def PATH = 'executor'
|
||||
|
||||
@AutoCleanup
|
||||
def aut = new CustomPortMainApplicationUnderTest(8888)
|
||||
|
||||
void 'transaction sent to executor'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
transaction.end()
|
||||
when:
|
||||
String json = aut.httpClient.requestSpec{ spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.postText(PATH)
|
||||
def recievedTransaction = mapper.readValue(json, BlockTransaction)
|
||||
then:
|
||||
recievedTransaction.id == transaction.id
|
||||
recievedTransaction.completed
|
||||
recievedTransaction.executed
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
90
dbt-test/src/test/groovy/com/devsoap/dbt/LedgerSpec.groovy
Normal file
90
dbt-test/src/test/groovy/com/devsoap/dbt/LedgerSpec.groovy
Normal file
@@ -0,0 +1,90 @@
|
||||
package com.devsoap.dbt
|
||||
|
||||
import com.devsoap.dbt.data.BlockTransaction
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import groovy.json.JsonSlurper
|
||||
import ratpack.groovy.test.GroovyRatpackMainApplicationUnderTest
|
||||
import ratpack.impose.Imposition
|
||||
import ratpack.impose.Impositions
|
||||
import ratpack.impose.ImpositionsSpec
|
||||
import ratpack.impose.ServerConfigImposition
|
||||
import ratpack.server.RatpackServer
|
||||
import spock.lang.AutoCleanup
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
|
||||
class LedgerSpec extends Specification {
|
||||
|
||||
def mapper = new ObjectMapper()
|
||||
|
||||
def PATH = 'ledger'
|
||||
|
||||
@AutoCleanup
|
||||
GroovyRatpackMainApplicationUnderTest aut = new CustomPortMainApplicationUnderTest(8888)
|
||||
|
||||
void 'transaction sent to ledger'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
when:
|
||||
String json = aut.httpClient.requestSpec{ spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.postText(PATH)
|
||||
def recievedTransaction = mapper.readValue(json, BlockTransaction)
|
||||
then:
|
||||
recievedTransaction.id == transaction.id
|
||||
!recievedTransaction.completed
|
||||
}
|
||||
|
||||
void 'completed transaction marked as completed'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
transaction.end()
|
||||
when:
|
||||
String json = aut.httpClient.requestSpec{ spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.postText(PATH)
|
||||
def recievedTransaction = mapper.readValue(json, BlockTransaction)
|
||||
then:
|
||||
recievedTransaction.id == transaction.id
|
||||
recievedTransaction.completed
|
||||
}
|
||||
|
||||
void 'completed transaction sent to executor from ledger'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
transaction.end()
|
||||
when:
|
||||
def response = mapper.readValue(aut.httpClient.requestSpec { spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.post(PATH).body.text, BlockTransaction)
|
||||
then:
|
||||
response.id == transaction.id
|
||||
response.executed == true
|
||||
response.rolledback == false
|
||||
response.completed == true
|
||||
}
|
||||
|
||||
void 'result is attached to block and executed in order'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("INSERT INTO LOGS(LOG_ID,LOG_VALUE) VALUES (1, 'HELLO')")
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
transaction.end()
|
||||
when:
|
||||
String json = aut.httpClient.requestSpec{ spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.postText(PATH)
|
||||
def recievedTransaction = mapper.readValue(json, BlockTransaction)
|
||||
def result = recievedTransaction.queries[1].result
|
||||
then:
|
||||
recievedTransaction.id == transaction.id
|
||||
recievedTransaction.queries.first().result == null // insert query has no result
|
||||
|
||||
result['LOG_ID'].first() == 1
|
||||
result['LOG_VALUE'].first() == 'HELLO'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.devsoap.dbt
|
||||
|
||||
import com.devsoap.dbt.data.BlockTransaction
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import ratpack.groovy.test.GroovyRatpackMainApplicationUnderTest
|
||||
import spock.lang.AutoCleanup
|
||||
import spock.lang.Specification
|
||||
|
||||
class TransactionManagementServiceSpec extends Specification {
|
||||
|
||||
def mapper = new ObjectMapper()
|
||||
|
||||
def PATH = 'ledger'
|
||||
|
||||
@AutoCleanup
|
||||
GroovyRatpackMainApplicationUnderTest aut = new CustomPortMainApplicationUnderTest(8888)
|
||||
|
||||
void 'transaction sent to ledger'() {
|
||||
setup:
|
||||
def transaction = new BlockTransaction()
|
||||
transaction.execute("SELECT * FROM LOGS")
|
||||
when:
|
||||
String json = aut.httpClient.requestSpec{ spec ->
|
||||
spec.body.text(mapper.writeValueAsString(transaction))
|
||||
}.postText(PATH)
|
||||
def recievedTransaction = mapper.readValue(json, BlockTransaction)
|
||||
then:
|
||||
recievedTransaction.id == transaction.id
|
||||
!recievedTransaction.completed
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
create table LOGS (
|
||||
LOG_ID int not null,
|
||||
LOG_VALUE varchar(100) not null
|
||||
);
|
||||
Reference in New Issue
Block a user