Skip to content

Api rework, code refactoring#11

Draft
Toru8P wants to merge 62 commits intodevfrom
refactoring
Draft

Api rework, code refactoring#11
Toru8P wants to merge 62 commits intodevfrom
refactoring

Conversation

@Toru8P
Copy link

@Toru8P Toru8P commented May 5, 2022

Needed stable api to have a possibility to validate request or send response after
Trying to clean server class to be useable separeted from common logic
Updated package path and copyright
Trying to use th2-client as multi-thread test http client

Nikita Shaposhnikov and others added 30 commits August 2, 2021 19:58
@Toru8P Toru8P self-assigned this May 5, 2022
@Toru8P Toru8P marked this pull request as draft May 5, 2022 01:39
@Toru8P Toru8P requested a review from cordwelt May 5, 2022 01:39
cleaner.schedule(checkSockets, socketDelayCheck * 1000, socketDelayCheck * 1000)
}

fun removeSocket(key: String) = dialogues.remove(key).apply { LOGGER.debug("Inactive socket [$key] was removed from store") }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be private

private fun handle(client: Socket, parentEventId: String) {
if (!client.isConnected || client.isClosed || client.isInputShutdown) {
options.onError("Cannot handle socket [closed]: $socket", parentEventId, IllegalStateException())
options.onError("Cannot handle socket [closed]: $socket", exception = null, parentEventId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exception = null

Maybe make exception argument optional too?

val mapper = JsonMapper.builder()
.addModule(KotlinModule(nullIsSameAsDefault = true))
.build()
val mapper = ObjectMapper(YAMLFactory()).apply {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YAMLFactory()

custom config is loaded from JSON file

}, rootEventId).id
init(StateManagerContext(server, stateManagerEvent, eventStore))
val stateManagerEvent = eventStore(
Event.start().endTimestamp().name("State manager"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.endTimestamp()

Looks like its optional and will be automatically set during conversion to proto-event

Comment on lines 205 to 207
sendAll(MessageGroupBatch.newBuilder().addGroups(MessageGroup.newBuilder().apply {
this += message
}).build(), *attribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sendAll(MessageGroupBatch.newBuilder().addGroups(MessageGroup.newBuilder().apply {
this += message
}).build(), *attribute)
sendAll(MessageGroupBatch.newBuilder().apply { addGroupsBuilder() += message }.build(), *attribute)

@@ -0,0 +1,3 @@
package com.exactpro.th2.http.server.api

interface IStateManagerSettings {} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface IStateManagerSettings {}
interface IStateManagerSettings

val kmf: KeyManagerFactory = KeyManagerFactory.getInstance(settings.keyManagerAlgorithm)
val ks: KeyStore = KeyStore.getInstance(settings.keystoreType)
when {
settings.keystorePath.isEmpty() -> this::class.java.classLoader.getResourceAsStream("defaultkeystore").use { ks.load(it, passphrase) }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
settings.keystorePath.isEmpty() -> this::class.java.classLoader.getResourceAsStream("defaultkeystore").use { ks.load(it, passphrase) }
settings.keystorePath.isEmpty() -> this::class.java.getResourceAsStream("defaultkeystore").use { ks.load(it, passphrase) }

while (error != null) {
bodyData(EventUtils.createMessageBean(error.message))
error = error.cause
exception?.let {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant

} No newline at end of file
}

fun MessageGroup.getParentEventId() = messagesList.mapNotNull {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fun MessageGroup.getParentEventId() = messagesList.mapNotNull {
fun MessageGroup.getParentEventId() = messagesList.mapNotNullTo(HashSet()) {

Comment on lines +75 to +79
eventId = when {
head.hasParentEventId() -> head.parentEventId
body.hasParentEventId() -> body.parentEventId
else -> EventID.getDefaultInstance()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
eventId = when {
head.hasParentEventId() -> head.parentEventId
body.hasParentEventId() -> body.parentEventId
else -> EventID.getDefaultInstance()
}
eventId = if (head.hasParentEventId()) head.parentEventId else body.parentEventId

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants