-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for SQL Server #200
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,9 @@ done; | |
} | ||
rm ./bintray.sbt | ||
|
||
wait 5432 PostgreSQL | ||
wait 3306 MySQL | ||
wait 1521 Oracle | ||
wait 1433 SqlSever | ||
|
||
sbt test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# | ||
# Copyright 2016 Dennis Vriend | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
#!/bin/bash | ||
export VM_HOST="${VM_HOST:-localhost}" | ||
|
||
# Wait for a certain service to become available | ||
# Usage: wait 1433 SqlServer | ||
wait() { | ||
while true; do | ||
if ! nc -z $VM_HOST $1 | ||
then | ||
echo "$2 not available, retrying..." | ||
sleep 1 | ||
else | ||
echo "$2 is available" | ||
break; | ||
fi | ||
done; | ||
} | ||
|
||
docker-compose -f scripts/sqlserver.yml kill | ||
docker-compose -f scripts/sqlserver.yml rm -f | ||
docker-compose -f scripts/sqlserver.yml up -d | ||
wait 1433 SqlServer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/bash | ||
echo "================== Help for SqlServer cli ========================" | ||
echo "=================================================================" | ||
docker exec -it sqlserver /opt/mssql-tools/bin/sqlcmd -S localhost -U docker -P docker -d docker |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
sqlserver: | ||
image: topaztechnology/mssql-server-linux | ||
container_name: sqlserver | ||
environment: | ||
- "TZ=Europe/Amsterdam" | ||
- "DBCA_TOTAL_MEMORY=1024" | ||
- "ACCEPT_EULA=Y" | ||
- "SQL_USER=docker" | ||
- "SQL_PASSWORD=docker" | ||
- "SQL_DB=docker" | ||
ports: | ||
- "1433:1433" # credentials (docker:docker) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,6 @@ | |
package akka.persistence.jdbc | ||
package journal.dao | ||
|
||
import java.io.NotSerializableException | ||
|
||
import akka.{ Done, NotUsed } | ||
import akka.persistence.jdbc.config.JournalConfig | ||
import akka.persistence.jdbc.serialization.FlowPersistentReprSerializer | ||
|
@@ -28,7 +26,7 @@ import akka.stream.scaladsl.{ Keep, Sink, Source } | |
import akka.stream.{ Materializer, OverflowStrategy, QueueOfferResult } | ||
import org.slf4j.LoggerFactory | ||
import slick.jdbc.JdbcBackend._ | ||
import slick.jdbc.JdbcProfile | ||
import slick.jdbc.{ JdbcProfile, H2Profile } | ||
|
||
import scala.collection.immutable._ | ||
import scala.concurrent.{ ExecutionContext, Future, Promise } | ||
|
@@ -86,9 +84,14 @@ trait BaseByteArrayJournalDao extends JournalDaoWithUpdates { | |
} | ||
} | ||
|
||
private def writeJournalRows(xs: Seq[JournalRow]): Future[Unit] = for { | ||
_ <- db.run(queries.writeJournalRows(xs)) | ||
} yield () | ||
private def writeJournalRows(xs: Seq[JournalRow]): Future[Unit] = { | ||
if (slickProfile != H2Profile) | ||
// Write atomically without auto-commit | ||
db.run(queries.writeJournalRows(xs).transactionally).map(_ => Unit) | ||
else | ||
// However transactionally causes H2 tests to fail | ||
db.run(queries.writeJournalRows(xs)).map(_ => Unit) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why H2 is failing when using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot I had added this comment and merge it. In any case, I don't think we are doing any harm here. Actually, I run this locally without the if/else and calling Moreover, we don't need it transactionally because we have only one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the test failures were intermittent. Locally I also didn't have a problem, but maybe the Travis hardware was lower spec and caused the circuit breaker to time out. It's also not clear why this would reduce performance in H2 in the first place. With regards to not requiring |
||
} | ||
|
||
/** | ||
* @see [[akka.persistence.journal.AsyncWriteJournal.asyncWriteMessages(messages)]] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
DROP TABLE IF EXISTS journal; | ||
|
||
CREATE TABLE journal ( | ||
"ordering" BIGINT IDENTITY(1,1) NOT NULL, | ||
"deleted" BIT NULL DEFAULT 0, | ||
"persistence_id" VARCHAR(255) NOT NULL, | ||
"sequence_number" NUMERIC(10,0) NOT NULL, | ||
"tags" VARCHAR(255) NULL DEFAULT NULL, | ||
"message" VARBINARY(max) NOT NULL, | ||
PRIMARY KEY ("persistence_id", "sequence_number") | ||
); | ||
|
||
CREATE UNIQUE INDEX journal_ordering_idx ON journal (ordering); | ||
|
||
DROP TABLE IF EXISTS snapshot; | ||
|
||
CREATE TABLE snapshot ( | ||
"persistence_id" VARCHAR(255) NOT NULL, | ||
"sequence_number" NUMERIC(10,0) NOT NULL, | ||
"created" NUMERIC NOT NULL, | ||
"snapshot" VARBINARY(max) NOT NULL, | ||
PRIMARY KEY ("persistence_id", "sequence_number") | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2016 Dennis Vriend | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
// general.conf is included only for shared settings used for the akka-persistence-jdbc tests | ||
include "general.conf" | ||
include "sqlserver-application.conf" | ||
|
||
akka-persistence-jdbc.logicalDeletion.enable = false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Copyright 2016 Dennis Vriend | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
include "general.conf" | ||
|
||
akka { | ||
persistence { | ||
journal { | ||
plugin = "jdbc-journal" | ||
// Enable the line below to automatically start the journal when the actorsystem is started | ||
// auto-start-journals = ["jdbc-journal"] | ||
} | ||
snapshot-store { | ||
plugin = "jdbc-snapshot-store" | ||
// Enable the line below to automatically start the snapshot-store when the actorsystem is started | ||
// auto-start-snapshot-stores = ["jdbc-snapshot-store"] | ||
} | ||
} | ||
} | ||
|
||
jdbc-journal { | ||
tables { | ||
journal { | ||
tableName = "journal" | ||
schemaName = "dbo" | ||
} | ||
} | ||
|
||
slick = ${slick} | ||
} | ||
|
||
# the akka-persistence-snapshot-store in use | ||
jdbc-snapshot-store { | ||
tables { | ||
snapshot { | ||
tableName = "snapshot" | ||
schemaName = "dbo" | ||
} | ||
} | ||
|
||
slick = ${slick} | ||
} | ||
|
||
# the akka-persistence-query provider in use | ||
jdbc-read-journal { | ||
tables { | ||
journal { | ||
tableName = "journal" | ||
schemaName = "dbo" | ||
} | ||
} | ||
|
||
slick = ${slick} | ||
} | ||
|
||
slick { | ||
profile = "slick.jdbc.SQLServerProfile$" | ||
db { | ||
host = ${docker.host} | ||
host = ${?SQLSERVER_HOST} | ||
port = "1433" | ||
port = ${?SQLSERVER_PORT} | ||
url = "jdbc:sqlserver://"${slick.db.host}":"${slick.db.port}";databaseName=docker;integratedSecurity=false" | ||
user = "docker" | ||
user = ${?SQLSERVER_USER} | ||
password = "docker" | ||
password = ${?SQLSERVER_PASSWORD} | ||
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" | ||
numThreads = 5 | ||
maxConnections = 5 | ||
minConnections = 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2016 Dennis Vriend | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
include "general.conf" | ||
|
||
akka { | ||
persistence { | ||
journal { | ||
plugin = "jdbc-journal" | ||
// Enable the line below to automatically start the journal when the actorsystem is started | ||
// auto-start-journals = ["jdbc-journal"] | ||
} | ||
snapshot-store { | ||
plugin = "jdbc-snapshot-store" | ||
// Enable the line below to automatically start the snapshot-store when the actorsystem is started | ||
// auto-start-snapshot-stores = ["jdbc-snapshot-store"] | ||
} | ||
} | ||
} | ||
|
||
akka-persistence-jdbc { | ||
shared-databases { | ||
slick { | ||
profile = "slick.jdbc.SQLServerProfile$" | ||
db { | ||
host = ${docker.host} | ||
host = ${?SQLSERVER_HOST} | ||
url = "jdbc:sqlserver://"${akka-persistence-jdbc.shared-databases.slick.db.host}":1433;databaseName=docker;integratedSecurity=false;" | ||
user = "docker" | ||
user = ${?SQLSERVER_USER} | ||
// This password needs to include at least 8 characters of at least three of these four categories: | ||
// uppercase letters, lowercase letters, numbers and non-alphanumeric symbols. | ||
password = "docker" | ||
password = ${?SQLSERVER_PASSWORD} | ||
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver" | ||
numThreads = 5 | ||
maxConnections = 5 | ||
minConnections = 1 | ||
} | ||
} | ||
} | ||
} | ||
|
||
jdbc-journal { | ||
use-shared-db = "slick" | ||
} | ||
|
||
# the akka-persistence-snapshot-store in use | ||
jdbc-snapshot-store { | ||
use-shared-db = "slick" | ||
} | ||
|
||
# the akka-persistence-query provider in use | ||
jdbc-read-journal { | ||
use-shared-db = "slick" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, PostgreSQL was not included by default?