Skip to content

Commit

Permalink
chore(queue): removed envelope handling code we don't use
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Sep 15, 2017
1 parent 86c8e1b commit 4a149cd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.netflix.spinnaker.orca.q.redis
import com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.google.common.hash.Hashing
import com.netflix.spinnaker.orca.q.AttemptsAttribute
import com.netflix.spinnaker.orca.q.MaxAttemptsAttribute
Expand Down Expand Up @@ -67,18 +66,6 @@ class RedisQueue(
private val hashKey = "$queueName.hash"
private val hashesKey = "$queueName.hashes"

companion object {
fun convertToMessage(json: String, mapper: ObjectMapper): Message {
val messageMap = mapper.readValue<Map<String, Any>>(json)

return if (messageMap.containsKey("payload")) {
mapper.convertValue(messageMap.get("payload"), Message::class.java)
} else {
mapper.readValue<Message>(json)
}
}
}

override fun poll(callback: (Message, () -> Unit) -> Unit) {
pool.resource.use { redis ->
redis.zrangeByScore(queueKey, 0.0, score(), 0, 1)
Expand Down Expand Up @@ -253,11 +240,11 @@ class RedisQueue(
removeMessage(id)
} else {
try {
val message = convertToMessage(json, mapper)
val message = mapper.readValue<Message>(json)

// TODO: AttemptsAttribute could replace `attemptsKey`
message.setAttribute(
message.getAttribute<AttemptsAttribute>(AttemptsAttribute())
message.getAttribute(AttemptsAttribute())
).increment()
hset(messagesKey, id, mapper.writeValueAsString(message))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@

package com.netflix.spinnaker.orca.q.redis

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.netflix.spinnaker.kork.jedis.EmbeddedRedis
import com.netflix.spinnaker.orca.pipeline.model.Pipeline
import com.netflix.spinnaker.orca.q.DeadMessageCallback
import com.netflix.spinnaker.orca.q.Message
import com.netflix.spinnaker.orca.q.QueueTest
import com.netflix.spinnaker.orca.q.StartExecution
import com.netflix.spinnaker.orca.q.metrics.MonitorableQueueTest
import org.funktionale.partials.invoke
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import org.junit.Assert
import org.springframework.context.ApplicationEvent
import org.springframework.context.ApplicationEventPublisher
import java.time.Clock
Expand Down Expand Up @@ -63,29 +54,3 @@ private val createQueue = { clock: Clock,
private fun shutdownCallback() {
redis?.destroy()
}

class ConvertToMessageSpec : Spek({
describe("should support deserializing a nested message") {
val objectMapper = ObjectMapper().apply {
registerModule(KotlinModule())
}

val message = StartExecution(Pipeline::class.java, "1", "foo")

it("is not nested") {
Assert.assertEquals(
message,
RedisQueue.convertToMessage(objectMapper.writeValueAsString(message), objectMapper)
)
}

it("is nested") {
Assert.assertEquals(
message,
RedisQueue.convertToMessage(objectMapper.writeValueAsString(Envelope(message)), objectMapper)
)
}
}
})

private data class Envelope(val payload: Message)

0 comments on commit 4a149cd

Please sign in to comment.