Skip to content

Commit

Permalink
Added missing Refleshable to FallbackNewRelicInsightsServiceSpec (#40)
Browse files Browse the repository at this point in the history
* Added missing Refleshable to FallbackNewRelicInsightsServiceSpec

* added missing license header
  • Loading branch information
musketyr authored Sep 26, 2024
1 parent 2b48631 commit 8d6d5d3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.micronaut.context.annotation.Secondary;
import io.micronaut.context.event.ApplicationEventListener;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.runtime.context.scope.Refreshable;
import io.micronaut.runtime.context.scope.refresh.RefreshEvent;
import jakarta.inject.Singleton;
import jakarta.validation.Valid;
Expand All @@ -37,7 +38,8 @@

@Secondary
@Singleton
public class FallbackNewRelicInsightsService implements NewRelicInsightsService, ApplicationEventListener<RefreshEvent> {
@Refreshable
public class FallbackNewRelicInsightsService implements NewRelicInsightsService, ApplicationEventListener<RefreshEvent>, AutoCloseable {

private static final int MAX_EVENTS = 25;
private static final Logger LOGGER = LoggerFactory.getLogger(NewRelicInsightsService.class);
Expand Down Expand Up @@ -84,4 +86,9 @@ public void onApplicationEvent(RefreshEvent event) {
events.clear();
}

@Override
public void close() {
events.clear();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2022-2024 Agorapulse.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nr

import com.agorapulse.micronaut.newrelic.FallbackNewRelicInsightsService
import com.agorapulse.micronaut.newrelic.NewRelicInsightsEvent
import groovy.transform.CompileDynamic
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Specification

@CompileDynamic
@MicronautTest
class FallbackNewRelicInsightsServiceSpec extends Specification {

@Inject FallbackNewRelicInsightsService service

void 'events are reset 1'() {
expect:
service.getEvents(NewRelicInsightsEvent).count() == 0
when:
service.createEvent(NewRelicInsightsEvent.create('TestEvent', 'order', 1))
then:
service.getEvents(NewRelicInsightsEvent).count() == 1
}

void 'events are reset 2'() {
expect:
service.getEvents(NewRelicInsightsEvent).count() == 0
when:
service.createEvent(NewRelicInsightsEvent.create('TestEvent', 'order', 1))
then:
service.getEvents(NewRelicInsightsEvent).count() == 1
}

}

0 comments on commit 8d6d5d3

Please sign in to comment.