Skip to content

Commit

Permalink
Merge pull request #41 from discipl/small-fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
TristanAlbers authored Nov 11, 2021
2 parents 4d887b1 + 7e92728 commit eb8d05b
Show file tree
Hide file tree
Showing 14 changed files with 4,377 additions and 4,693 deletions.
2 changes: 1 addition & 1 deletion code/java/FlintSources/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies {

implementation "io.ktor:ktor-client-logging:$ktor_version"
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-cio:$ktor_version"
implementation "io.ktor:ktor-client-apache:$ktor_version"
implementation "io.ktor:ktor-client-gson:$ktor_version"

testImplementation "io.ktor:ktor-client-mock:$ktor_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package org.discipl.flint.sources

import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.engine.cio.*
import io.ktor.client.engine.apache.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.client.features.logging.*
import io.ktor.client.request.*
import io.ktor.http.*
import org.apache.http.client.HttpClient
import org.apache.http.client.config.RequestConfig
Expand All @@ -27,6 +26,8 @@ import org.discipl.flint.sources.services.triply.SourceServiceImpl
import org.discipl.flint.sources.services.triply.TextLineServiceImpl
import org.discipl.flint.sources.services.triply.VersionServiceImpl
import org.discipl.flint.sources.transformers.*
import org.koin.core.Koin
import org.koin.core.KoinApplication
import org.koin.core.component.KoinApiExtension
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand All @@ -36,6 +37,7 @@ import org.koin.dsl.module
import java.net.URL
import java.util.concurrent.Callable
import java.util.concurrent.TimeUnit
import javax.net.ssl.SSLContext


internal val demoServiceModule = module {
Expand All @@ -45,6 +47,7 @@ internal val demoServiceModule = module {
}

internal val triplyClientsModule = module {
single { SSLContext.getDefault() }
single<HttpClient> {
val timeoutInS = 20
val config = RequestConfig.custom()
Expand All @@ -53,6 +56,7 @@ internal val triplyClientsModule = module {
.setSocketTimeout(timeoutInS * 1000).build()
HttpClients.custom()
.setConnectionReuseStrategy { _, _ -> false }
.setSSLContext(get())
.setConnectionTimeToLive(timeoutInS.toLong(), TimeUnit.SECONDS)
.setDefaultRequestConfig(config)
.build()
Expand All @@ -64,12 +68,13 @@ internal val triplyClientsModule = module {
}

internal val nsxClientsModule = module(override = true) {
single { SSLContext.getDefault() }
single<JsonSerializer> {
GsonSerializer {
registerTypeAdapter(NsxEmbeddedResult::class.java, NsxEmbeddedResultDeserializer())
}
}
single<HttpClientEngine> { CIO.create {} }
single<HttpClientEngine> { Apache.create { sslContext = get() } }
single {
HttpClient(get()) {
defaultRequest {
Expand Down Expand Up @@ -98,12 +103,17 @@ internal val nsxClientsModule = module(override = true) {

@Suppress("EXPERIMENTAL_API_USAGE")
internal val hybridClientModule = module(override = true) {
single { SSLContext.getDefault() }
single<JsonSerializer> {
GsonSerializer {
registerTypeAdapter(NsxEmbeddedResult::class.java, NsxEmbeddedResultDeserializer())
}
}
single<HttpClientEngine> { CIO.create {} }
single<HttpClientEngine> {
Apache.create {
sslContext = get()
}
}
single {
HttpClient(get()) {
defaultRequest {
Expand Down Expand Up @@ -131,6 +141,7 @@ internal val hybridClientModule = module(override = true) {
.setSocketTimeout(timeoutInS * 1000).build()
HttpClients.custom()
.setConnectionReuseStrategy { _, _ -> false }
.setSSLContext(get())
.setConnectionTimeToLive(timeoutInS.toLong(), TimeUnit.SECONDS)
.setDefaultRequestConfig(config)
.build()
Expand Down Expand Up @@ -176,11 +187,22 @@ val serviceModule = hybrideServiceModule

@KoinApiExtension
object SourceLoader : KoinComponent {
private val koinApp = startKoin {
modules(serviceModule)
private lateinit var koinApp: KoinApplication
fun initWith(sslContext: SSLContext) {
koinApp = startKoin {
modules(serviceModule, module { single(override = true) { sslContext } })
}
}

override fun getKoin(): Koin {
if (!this::koinApp.isInitialized) {
koinApp = startKoin {
modules(serviceModule)
}
}
return koinApp.koin
}

override fun getKoin() = koinApp.koin
val articleService: ArticleService by inject()
val asyncArticleService: AsyncArticleService by inject()
val parserService: ParserService by inject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.discipl.flint.sources.models
class Article(override val id: String) : IHasParts {
private val _parts = mutableListOf<Part>()
val name get() = (_parts.first { it is ArticleTitle } as ArticleTitle).text
val nameLineNumber get() = (_parts.first { it is ArticleTitle } as ArticleTitle).lineNr
val articleTextParts get() = _parts.filter { it !is ArticleTitle }
override val parts: List<Part> get() = _parts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.koin.core.qualifier.Qualifier
import org.koin.core.qualifier.named
import org.koin.dsl.module
import java.util.concurrent.Callable
import javax.net.ssl.SSLContext

@Suppress("EXPERIMENTAL_API_USAGE", "EXPERIMENTAL_OVERRIDE")
object TestSourceLoader : KoinComponent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal class AsyncArticleServiceImplTest {
do {
Thread.sleep(1000L)
status = getStatus()
} while (status != "Ready")
} while (status != "Ready" && status != "ParserInvokerFailed")

}
val status = getStatus()
Expand Down Expand Up @@ -113,7 +113,7 @@ internal class AsyncArticleServiceImplTest {
do {
Thread.sleep(1000L)
status = getStatus()
} while (status != "Ready")
} while (status != "Ready" && status != "ParserInvokerFailed")

}
val status = getStatus()
Expand Down
2 changes: 1 addition & 1 deletion code/java/FlintSources/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
<appender-ref ref="STDOUT" />
</root>

<logger name="org.apache.http.wire" level="DEBUG"/>
<!-- <logger name="org.apache.http.wire" level="DEBUG"/>-->
</configuration>
Loading

0 comments on commit eb8d05b

Please sign in to comment.