blob: ac91aaeb77b86ca5d8e6a1574ef2121cf0c74a65 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
package org.onap.dcae.collectors.veshv.impl
import io.netty.buffer.Unpooled
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.onap.dcae.collectors.veshv.domain.VesMessage
import org.onap.dcae.collectors.veshv.domain.routing
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader
import org.onap.ves.VesEventV5.VesEvent.CommonEventHeader.Domain
/**
* @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
* @since May 2018
*/
object RouterTest : Spek({
given("sample configuration") {
val config = routing {
defineRoute {
fromDomain(Domain.HVRANMEAS)
toTopic("ves_rtpm")
withFixedPartitioning(2)
}
defineRoute {
fromDomain(Domain.SYSLOG)
toTopic("ves_trace")
withFixedPartitioning()
}
}.build()
val cut = Router(config)
on("message with existing route (rtpm)") {
val message = VesMessage(vesCommonHeaderWithDomain(Domain.HVRANMEAS), Unpooled.EMPTY_BUFFER)
val result = cut.findDestination(message)
it("should have route available") {
assertThat(result).isNotNull()
}
it("should be routed to proper partition") {
assertThat(result?.partition).isEqualTo(2)
}
it("should be routed to proper topic") {
assertThat(result?.topic).isEqualTo("ves_rtpm")
}
it("should be routed with a given message") {
assertThat(result?.message).isSameAs(message)
}
}
on("message with existing route (trace)") {
val message = VesMessage(vesCommonHeaderWithDomain(Domain.SYSLOG), Unpooled.EMPTY_BUFFER)
val result = cut.findDestination(message)
it("should have route available") {
assertThat(result).isNotNull()
}
it("should be routed to proper partition") {
assertThat(result?.partition).isEqualTo(1)
}
it("should be routed to proper topic") {
assertThat(result?.topic).isEqualTo("ves_trace")
}
it("should be routed with a given message") {
assertThat(result?.message).isSameAs(message)
}
}
on("message with unknown route") {
val message = VesMessage(vesCommonHeaderWithDomain(Domain.HEARTBEAT), Unpooled.EMPTY_BUFFER)
val result = cut.findDestination(message)
it("should not have route available") {
assertThat(result).isNull()
}
}
}
})
private fun vesCommonHeaderWithDomain(domain: Domain) =
CommonEventHeader.getDefaultInstance().toBuilder()
.setDomain(domain)
.build()
|