Skip to content

Commit

Permalink
Merge pull request #13 from Landoop/fix/login_plus_tests
Browse files Browse the repository at this point in the history
fix authenticate
  • Loading branch information
sksamuel authored Aug 9, 2018
2 parents c78aca9 + 82c6878 commit 8279c80
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
ext.slf4j_version = '1.7.25'
ext.joda_version = '2.9.9'
ext.avro_version = '1.8.2'
ext.httpclient_version = '4.5.3'
ext.httpclient_version = '4.5.6'
ext.jackson_version = '2.9.5'
ext.kafka_version = '0.11.0.2'
repositories {
Expand Down
26 changes: 11 additions & 15 deletions src/main/kotlin/com/landoop/jdbc4/client/RestClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@ package com.landoop.jdbc4.client

import com.landoop.jdbc4.Constants
import com.landoop.jdbc4.JacksonSupport
import com.landoop.jdbc4.client.domain.Credentials
import com.landoop.jdbc4.client.domain.InsertRecord
import com.landoop.jdbc4.client.domain.InsertResponse
import com.landoop.jdbc4.client.domain.Message
import com.landoop.jdbc4.client.domain.PreparedInsertResponse
import com.landoop.jdbc4.client.domain.StreamingSelectResult
import com.landoop.jdbc4.client.domain.Table
import com.landoop.jdbc4.client.domain.Topic
import com.landoop.jdbc4.client.domain.*
import org.apache.http.HttpEntity
import org.apache.http.HttpResponse
import org.apache.http.client.config.RequestConfig
Expand All @@ -28,15 +21,10 @@ import org.glassfish.tyrus.client.ClientProperties
import org.slf4j.LoggerFactory
import java.io.IOException
import java.net.URI
import java.net.URL
import java.net.URLEncoder
import java.sql.SQLException
import java.util.concurrent.Executors
import javax.websocket.ClientEndpointConfig
import javax.websocket.Endpoint
import javax.websocket.EndpointConfig
import javax.websocket.MessageHandler
import javax.websocket.Session
import javax.websocket.*

class RestClient(private val urls: List<String>,
private val credentials: Credentials,
Expand Down Expand Up @@ -168,7 +156,7 @@ class RestClient(private val urls: List<String>,
val entity = jsonEntity(credentials)
val endpoint = "$it/api/login"
logger.debug("Authenticating at $endpoint")
jsonPost(endpoint, entity)
jsonPostWithTextPlain(endpoint, entity)
}

val responseFn: (HttpResponse) -> String = {
Expand Down Expand Up @@ -395,5 +383,13 @@ class RestClient(private val urls: List<String>,
this.setHeader("Content-type", "application/json")
}
}

fun jsonPostWithTextPlain(endpoint: String, entity: HttpEntity): HttpPost {
return HttpPost(endpoint).apply {
this.entity = entity
this.setHeader("Accept", "text/plain")
this.setHeader("Content-type", "application/json")
}
}
}
}
2 changes: 1 addition & 1 deletion src/test/kotlin/com/landoop/jdbc4/BatchInsertTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BatchInsertTest : WordSpec(), CCData {

val batchSize = 20
val values = Array(batchSize, { _ -> generateCC() })
val sql = "INSERT INTO cc_data (customerFirstName, number, currency, customerLastName, country, blocked) values (?,?,?,?,?,?)"
val sql = "SET _ktype='STRING'; SET _vtype='AVRO';INSERT INTO cc_data (customerFirstName, number, currency, customerLastName, country, blocked) values (?,?,?,?,?,?)"
val stmt = conn.prepareStatement(sql)

for (value in values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BatchNestedInsertStressTest : WordSpec(), LocationData {
createTopic(topic)


val sql = "SET _ktype='STRING';INSERT INTO `$topic` (id, address.street, address.number, address.zip,address.state, geo.lat, geo.lon) values (?,?,?,?,?,?,?)"
val sql = "SET _ktype='STRING'; SET _vtype='AVRO';INSERT INTO `$topic` (id, address.street, address.number, address.zip,address.state, geo.lat, geo.lon) values (?,?,?,?,?,?,?)"
val stmt = conn.prepareStatement(sql)

locations.asList().chunked(batchSize).forEach { batch ->
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/landoop/jdbc4/PreparedInsertTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class PreparedInsertTest : WordSpec(), MovieData {

"JDBC Driver" should {
"support prepared statements" {
val sql = "INSERT INTO cc_data (customerFirstName, number, currency, customerLastName, country, blocked) values (?,?,?,?,?,?)"
val sql = "SET _ktype='STRING';INSERT INTO cc_data (customerFirstName, number, currency, customerLastName, country, blocked) values (?,?,?,?,?,?)"
val stmt = conn.prepareStatement(sql)
stmt.setString(1, "sammy")
stmt.setString(2, "4191005000501123")
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/landoop/jdbc4/RestClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RestClientTest : WordSpec() {

class LoginServer : NanoHTTPD(61864) {
override fun serve(session: IHTTPSession): Response {
return newFixedLengthResponse("""{"success":true, "token": "wibble"}""".trimIndent())
return newFixedLengthResponse("""wibble""".trimIndent())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/com/landoop/jdbc4/ScaleQueryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ScaleQueryTest : WordSpec(), ProducerSetup {
LsqlDriver()
populateEquities()

val q = "SELECT * FROM $topic"
val q = "SELECT * FROM $topic WHERE _ktype=STRING AND _vtype=AVRO"
val conn = DriverManager.getConnection("jdbc:lsql:kafka:http://localhost:3030", "admin", "admin")
val stmt = conn.createStatement()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,21 @@ class SingleFieldSchemaQueryTest : WordSpec(), ProducerSetup {

"JDBC Driver" should {
"support wildcard for fixed schemas" {
val q = "SELECT * FROM $topic"
val q = "SELECT * FROM $topic WHERE _ktype=STRING and _vtype=AVRO"
val stmt = conn().createStatement()
val rs = stmt.executeQuery(q)
rs.metaData.columnCount shouldBe 1
rs.metaData.getColumnLabel(1) shouldBe "name"
}
"support projection for fixed schemas" {
val q = "SELECT name FROM $topic"
val q = "SELECT name FROM $topic WHERE _ktype=STRING and _vtype=AVRO"
val stmt = conn().createStatement()
val rs = stmt.executeQuery(q)
rs.metaData.columnCount shouldBe 1
rs.metaData.getColumnLabel(1) shouldBe "name"
}
"return data for fixed schema" {
val q = "SELECT * FROM $topic"
val q = "SELECT * FROM $topic WHERE _ktype=STRING and _vtype=AVRO"
val stmt = conn().createStatement()
stmt.execute(q) shouldBe true
val rs = stmt.resultSet
Expand Down

0 comments on commit 8279c80

Please sign in to comment.