@@ -3,6 +3,7 @@ package io.micronaut.aws.cloudwatch.logging
3
3
import ch.qos.logback.classic.Level
4
4
import ch.qos.logback.classic.LoggerContext
5
5
import ch.qos.logback.classic.PatternLayout
6
+ import ch.qos.logback.classic.spi.ILoggingEvent
6
7
import ch.qos.logback.classic.spi.LoggingEvent
7
8
import ch.qos.logback.core.encoder.LayoutWrappingEncoder
8
9
import io.micronaut.runtime.ApplicationConfiguration
@@ -64,6 +65,7 @@ class CloudWatchLoggingAppenderSpec extends Specification {
64
65
void ' test error queue size equal to 0' () {
65
66
when :
66
67
appender. queueSize = 0
68
+ appender. dispatchOnStart = true
67
69
appender. start()
68
70
69
71
then :
@@ -75,6 +77,7 @@ class CloudWatchLoggingAppenderSpec extends Specification {
75
77
when :
76
78
appender. queueSize = 100
77
79
appender. publishPeriod = 0
80
+ appender. dispatchOnStart = true
78
81
appender. start()
79
82
80
83
then :
@@ -85,6 +88,7 @@ class CloudWatchLoggingAppenderSpec extends Specification {
85
88
void ' test error max batch size less or equal to 0' () {
86
89
when :
87
90
appender. maxBatchSize = 0
91
+ appender. dispatchOnStart = true
88
92
appender. start()
89
93
90
94
then :
@@ -97,6 +101,7 @@ class CloudWatchLoggingAppenderSpec extends Specification {
97
101
appender. queueSize = 100
98
102
appender. publishPeriod = 100
99
103
appender. encoder = null
104
+ appender. dispatchOnStart = true
100
105
appender. start()
101
106
102
107
then :
@@ -167,6 +172,49 @@ class CloudWatchLoggingAppenderSpec extends Specification {
167
172
thrown(UnsupportedOperationException )
168
173
}
169
174
175
+ void ' test start dispatch on start' () {
176
+ given :
177
+ PollingConditions conditions = new PollingConditions (timeout : 10 , initialDelay : 1.5 , factor : 1.25 )
178
+ LoggingEvent event = createEvent(" name" , Level . INFO , " testMessage" , System . currentTimeMillis())
179
+
180
+ when :
181
+ appender. dispatchOnStart = true
182
+ appender. start()
183
+ appender. doAppend(event)
184
+
185
+ then :
186
+ conditions. eventually {
187
+ cloudWatchLogsClient. putLogsRequestList. size() == 1
188
+ }
189
+ cloudWatchLogsClient. putLogsRequestList. get(0 ). logEvents()[0 ]. message(). contains(" testMessage" )
190
+ }
191
+
192
+ void ' test start dispatch on append' () {
193
+ given :
194
+ PollingConditions conditions = new PollingConditions (timeout : 10 , initialDelay : 1.5 , factor : 1.25 )
195
+ LoggingEvent event = createEvent(" name" , Level . INFO , " testMessage" , System . currentTimeMillis())
196
+
197
+ when :
198
+ appender. groupName = " testGroup"
199
+ appender. streamName = " testStream"
200
+ appender. start()
201
+
202
+ then :
203
+ conditions. within(1 ) {
204
+ cloudWatchLogsClient. putLogsRequestList. size() == 0
205
+ }
206
+
207
+ when :
208
+ appender. doAppend(event)
209
+
210
+ then :
211
+ conditions. eventually {
212
+ cloudWatchLogsClient. putLogsRequestList. size() == 1
213
+ }
214
+ cloudWatchLogsClient. putLogsRequestList. get(0 ). logEvents()[0 ]. message(). contains(" testMessage" )
215
+ cloudWatchLogsClient. putLogsRequestList. get(0 ). logStreamName() == " testStream"
216
+ }
217
+
170
218
void ' custom groupName and StreamName' () {
171
219
given :
172
220
def testGroup = " testGroup"
@@ -178,6 +226,7 @@ class CloudWatchLoggingAppenderSpec extends Specification {
178
226
when :
179
227
appender. groupName = testGroup
180
228
appender. streamName = testStream
229
+ appender. dispatchOnStart = true
181
230
appender. start()
182
231
appender. doAppend(event)
183
232
0 commit comments