Skip to content

Commit

Permalink
use String instead of scala.Symbol in test
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Aug 15, 2020
1 parent c2e5cb9 commit cfb6a15
Show file tree
Hide file tree
Showing 27 changed files with 145 additions and 145 deletions.
6 changes: 3 additions & 3 deletions scalikejdbc-core/src/test/scala/BasicUsageSpec.scala
Expand Up @@ -29,7 +29,7 @@ class BasicUsageSpec extends AnyFlatSpec with Matchers with LoanPattern {
// create singleton(default) connection pool
ConnectionPool.singleton(url, user, password, poolSettings)
// named connection pool
ConnectionPool.add(Symbol("named"), url, user, password, poolSettings)
ConnectionPool.add("named", url, user, password, poolSettings)

// ---------------------------
// Borrow a connection from the ConnectionPool
Expand All @@ -51,7 +51,7 @@ class BasicUsageSpec extends AnyFlatSpec with Matchers with LoanPattern {
}

it should "borrow a connection from named ConnectionPool" in {
using(ConnectionPool(Symbol("named")).borrow()) { conn =>
using(ConnectionPool("named").borrow()) { conn =>
conn should not be null
}
}
Expand Down Expand Up @@ -95,7 +95,7 @@ class BasicUsageSpec extends AnyFlatSpec with Matchers with LoanPattern {
}

// named datasources
NamedDB(Symbol("named")) autoCommit { session =>
NamedDB("named") autoCommit { session =>
session.list("select * from " + tableName)(rs => rs.int("id"))
}

Expand Down
16 changes: 8 additions & 8 deletions scalikejdbc-core/src/test/scala/models/Member.scala
Expand Up @@ -161,23 +161,23 @@ object NamedMember {
createdAt = rs.get(createdAt))
}

def find(id: Long)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): Option[NamedMember] = {
def find(id: Long)(implicit session: DBSession = NamedAutoSession("named")): Option[NamedMember] = {
SQL("""SELECT * FROM NAMED_MEMBER WHERE ID = /*'id*/1""").bindByName(Symbol("id") -> id).map(*).single.apply()
}

def findAll()(implicit session: DBSession = NamedAutoSession(Symbol("named"))): List[NamedMember] = {
def findAll()(implicit session: DBSession = NamedAutoSession("named")): List[NamedMember] = {
SQL("""SELECT * FROM NAMED_MEMBER""").map(*).list.apply()
}

def countAll()(implicit session: DBSession = NamedAutoSession(Symbol("named"))): Long = {
def countAll()(implicit session: DBSession = NamedAutoSession("named")): Long = {
SQL("""SELECT COUNT(1) FROM NAMED_MEMBER""").map(rs => rs.long(1)).single.apply().get
}

def findBy(where: String, params: (Symbol, Any)*)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): List[NamedMember] = {
def findBy(where: String, params: (Symbol, Any)*)(implicit session: DBSession = NamedAutoSession("named")): List[NamedMember] = {
SQL("""SELECT * FROM NAMED_MEMBER WHERE """ + where).bindByName(params: _*).map(*).list.apply()
}

def countBy(where: String, params: (Symbol, Any)*)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): Long = {
def countBy(where: String, params: (Symbol, Any)*)(implicit session: DBSession = NamedAutoSession("named")): Long = {
SQL("""SELECT count(1) FROM NAMED_MEMBER WHERE """ + where).bindByName(params: _*).map(rs => rs.long(1)).single.apply().get
}

Expand All @@ -186,7 +186,7 @@ object NamedMember {
name: String,
description: Option[String] = None,
birthday: Option[LocalDate] = None,
createdAt: LocalDateTime)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): NamedMember = {
createdAt: LocalDateTime)(implicit session: DBSession = NamedAutoSession("named")): NamedMember = {
SQL("""
INSERT INTO NAMED_MEMBER (
ID,
Expand Down Expand Up @@ -217,7 +217,7 @@ object NamedMember {
createdAt = createdAt)
}

def save(m: NamedMember)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): NamedMember = {
def save(m: NamedMember)(implicit session: DBSession = NamedAutoSession("named")): NamedMember = {
SQL("""
UPDATE
NAMED_MEMBER
Expand All @@ -239,7 +239,7 @@ object NamedMember {
m
}

def delete(m: NamedMember)(implicit session: DBSession = NamedAutoSession(Symbol("named"))): Unit = {
def delete(m: NamedMember)(implicit session: DBSession = NamedAutoSession("named")): Unit = {
SQL("""DELETE FROM NAMED_MEMBER WHERE ID = /*'id*/1""")
.bindByName(Symbol("id") -> m.id).update.apply()
}
Expand Down
4 changes: 2 additions & 2 deletions scalikejdbc-core/src/test/scala/models/MemberSpec.scala
Expand Up @@ -76,7 +76,7 @@ class MemberSpec extends AnyFlatSpec with Matchers with Settings {

it should "be available with NamedDB" in {

NamedDB(Symbol("named")) autoCommit { implicit session =>
NamedDB("named") autoCommit { implicit session =>
try {
SQL("drop table NAMED_MEMBER").execute.apply()
} catch {
Expand Down Expand Up @@ -110,7 +110,7 @@ class MemberSpec extends AnyFlatSpec with Matchers with Settings {
newAlice.destroy()

try {
NamedDB(Symbol("named")) localTx { implicit session =>
NamedDB("named") localTx { implicit session =>
NamedMember.create(
id = 999,
name = "Rollback",
Expand Down
Expand Up @@ -19,19 +19,19 @@ class AuthenticatedDataSourceConnectionPoolSpec extends AnyFlatSpec with Matcher
val dataSource: DataSource = mock(classOf[DataSource])
val dataSourceCloser = DummyDataSourceCloser()
val instance = new AuthenticatedDataSourceConnectionPool(dataSource, "user", "password ", closer = dataSourceCloser)
ConnectionPool.add(Symbol("close"), instance)
ConnectionPool.add("close", instance)
Thread.sleep(100L)
ConnectionPool.close(Symbol("close"))
ConnectionPool.close("close")
dataSourceCloser.closed shouldBe true
}

it should "be impossible to close with DefaultDataSourceCloser" in {
val dataSource: DataSource = mock(classOf[DataSource])
val instance = new AuthenticatedDataSourceConnectionPool(dataSource, "user", "password")
ConnectionPool.add(Symbol("close"), instance)
ConnectionPool.add("close", instance)
Thread.sleep(100L)
assertThrows[UnsupportedOperationException] {
ConnectionPool.close(Symbol("close"))
ConnectionPool.close("close")
}
}

Expand Down
Expand Up @@ -36,18 +36,18 @@ class ConnectionPoolSpec extends AnyFlatSpec with Matchers {
Thread.sleep(100L)
ConnectionPool.singleton(url, user, password, poolSettings)

ConnectionPool.add(Symbol("secondary"), url, user, password, poolSettings)
ConnectionPool.add("secondary", url, user, password, poolSettings)

using(ConnectionPool.borrow(Symbol("secondary"))) { conn =>
using(ConnectionPool.borrow("secondary")) { conn =>
conn should not be (null)
}

Thread.sleep(100L)
ConnectionPool.add(Symbol("secondary"), url, user, password, poolSettings)
ConnectionPool.add("secondary", url, user, password, poolSettings)
Thread.sleep(100L)
ConnectionPool.add(Symbol("secondary"), url, user, password, poolSettings)
ConnectionPool.add("secondary", url, user, password, poolSettings)
Thread.sleep(100L)
ConnectionPool.add(Symbol("secondary"), url, user, password, poolSettings)
ConnectionPool.add("secondary", url, user, password, poolSettings)

// this test code affects other tests
/*
Expand All @@ -67,9 +67,9 @@ class ConnectionPoolSpec extends AnyFlatSpec with Matchers {
}

it should "accept javax.sql.DataSource" in {
ConnectionPool.add(Symbol("sample"), url, user, password)
ConnectionPool.add("sample", url, user, password)
try {
NamedDB(Symbol("sample")) autoCommit { implicit s =>
NamedDB("sample") autoCommit { implicit s =>
try SQL("create table data_source_test(id bigint not null)").execute.apply()
catch { case e: Exception => e.printStackTrace }
SQL("insert into data_source_test values (123)").update.apply()
Expand All @@ -78,15 +78,15 @@ class ConnectionPoolSpec extends AnyFlatSpec with Matchers {
ds.setUrl(url)
ds.setUsername(user)
ds.setPassword(password)
ConnectionPool.add(Symbol("ds"), new DataSourceConnectionPool(ds))
ConnectionPool.add("ds", new DataSourceConnectionPool(ds))

NamedDB(Symbol("ds")) readOnly { implicit s =>
NamedDB("ds") readOnly { implicit s =>
val count = SQL("select count(1) from data_source_test").map(_.long(1)).single.apply().get
count should equal(1L)
}

} finally {
NamedDB(Symbol("sample")) autoCommit { implicit s =>
NamedDB("sample") autoCommit { implicit s =>
try SQL("drop table data_source_test").execute.apply()
catch { case e: Exception => e.printStackTrace }
}
Expand All @@ -112,15 +112,15 @@ class ConnectionPoolSpec extends AnyFlatSpec with Matchers {
}

implicit val factory = new MyConnectionPoolFactory
ConnectionPool.add(Symbol("xxxx"), url, user, password)
val conn = ConnectionPool.borrow(Symbol("xxxx"))
ConnectionPool.add("xxxx", url, user, password)
val conn = ConnectionPool.borrow("xxxx")
conn should be(null)

}

it should "throw exception if invalid connectionPoolFactoryName is given" in {
intercept[IllegalArgumentException](
ConnectionPool.add(Symbol("xxxx"), url, user, password,
ConnectionPool.add("xxxx", url, user, password,
ConnectionPoolSettings(connectionPoolFactoryName = "invalid")))
}

Expand Down
Expand Up @@ -22,23 +22,23 @@ class ConnectionPoolsSpec extends AnyFlatSpec with Matchers {
Class.forName(driverClassName)

it should "work" in {
ConnectionPool.add(Symbol("dbcp"), url, user, password, ConnectionPoolSettings(connectionPoolFactoryName = "commons-dbcp"))
ConnectionPool.add(Symbol("bonecp"), url, user, password, ConnectionPoolSettings(connectionPoolFactoryName = "bonecp"))
ConnectionPool.add("dbcp", url, user, password, ConnectionPoolSettings(connectionPoolFactoryName = "commons-dbcp"))
ConnectionPool.add("bonecp", url, user, password, ConnectionPoolSettings(connectionPoolFactoryName = "bonecp"))

val tableName = "connection_pool_" + System.currentTimeMillis
NamedDB(Symbol("dbcp")).autoCommit { implicit s =>
NamedDB("dbcp").autoCommit { implicit s =>
SQL(s"create table ${tableName} (id int, name varchar(256))").execute.apply()
SQL(s"insert into ${tableName} (id, name) values (1, 'commons-dbcp')").update.apply()
SQL(s"insert into ${tableName} (id, name) values (2, 'hikaricp')").update.apply()
SQL(s"insert into ${tableName} (id, name) values (3, 'bonecp')").update.apply()
}

NamedDB(Symbol("dbcp")).readOnly { implicit s =>
NamedDB("dbcp").readOnly { implicit s =>
val count = SQL(s"select count(1) from ${tableName}").map(_.long(1)).single.apply()
count should equal(Some(3))
}

NamedDB(Symbol("bonecp")).readOnly { implicit s =>
NamedDB("bonecp").readOnly { implicit s =>
val count = SQL(s"select count(1) from ${tableName}").map(_.long(1)).single.apply()
count should equal(Some(3))
}
Expand All @@ -52,9 +52,9 @@ class ConnectionPoolsSpec extends AnyFlatSpec with Matchers {
ds.addDataSourceProperty("password", password)
ds
}
ConnectionPool.add(Symbol("hikaricp"), new DataSourceConnectionPool(dataSource))
ConnectionPool.add("hikaricp", new DataSourceConnectionPool(dataSource))

NamedDB(Symbol("hikaricp")).readOnly { implicit s =>
NamedDB("hikaricp").readOnly { implicit s =>
val count = SQL(s"select count(1) from ${tableName}").map(_.long(1)).single.apply()
count should equal(Some(3))
}
Expand Down
Expand Up @@ -48,7 +48,7 @@ class DB_SessionOperationSpec extends AnyFlatSpec with Matchers with BeforeAndAf
}

"#tx" should "not be available before beginning tx" in {
using(ConnectionPool(Symbol("named")).borrow()) { conn =>
using(ConnectionPool("named").borrow()) { conn =>
val db = DB(conn)
intercept[IllegalStateException] {
db.tx.begin()
Expand Down
Expand Up @@ -19,19 +19,19 @@ class DataSourceConnectionPoolSpec extends AnyFlatSpec with Matchers {
val dataSource: DataSource = mock(classOf[DataSource])
val dataSourceCloser = DummyDataSourceCloser()
val instance = new DataSourceConnectionPool(dataSource, closer = dataSourceCloser)
ConnectionPool.add(Symbol("close"), instance)
ConnectionPool.add("close", instance)
Thread.sleep(100L)
ConnectionPool.close(Symbol("close"))
ConnectionPool.close("close")
dataSourceCloser.closed shouldBe true
}

it should "be impossible to close with DefaultDataSourceCloser" in {
val dataSource: DataSource = mock(classOf[DataSource])
val instance = new DataSourceConnectionPool(dataSource)
ConnectionPool.add(Symbol("close"), instance)
ConnectionPool.add("close", instance)
Thread.sleep(100L)
assertThrows[UnsupportedOperationException] {
ConnectionPool.close(Symbol("close"))
ConnectionPool.close("close")
}
}

Expand Down

0 comments on commit cfb6a15

Please sign in to comment.