+ @Test
+ fun `successful insert updates metrics`() {
+ val insertUri = mock<FreenetURI>()
+ val finalUri = mock<FreenetURI>()
+ createSone(insertUri)
+ val soneModificationDetector = mock<SoneModificationDetector>()
+ whenever(soneModificationDetector.isEligibleForInsert).thenReturn(true)
+ whenever(freenetInterface.insertDirectory(eq(insertUri), any<HashMap<String, Any>>(), eq("index.html"))).thenReturn(finalUri)
+ val soneInserter = SoneInserter(core, eventBus, freenetInterface, metricRegistry,"SoneId", soneModificationDetector, 1)
+ doAnswer {
+ soneInserter.stop()
+ null
+ }.whenever(core).touchConfiguration()
+ soneInserter.serviceRun()
+ val histogram = metricRegistry.histogram("sone.insert.duration")
+ assertThat(histogram.count, equalTo(1L))
+ }
+
+ @Test
+ fun `unsuccessful insert does not update histogram but records error`() {
+ val insertUri = mock<FreenetURI>()
+ createSone(insertUri)
+ val soneModificationDetector = mock<SoneModificationDetector>()
+ whenever(soneModificationDetector.isEligibleForInsert).thenReturn(true)
+ val soneInserter = SoneInserter(core, eventBus, freenetInterface, metricRegistry, "SoneId", soneModificationDetector, 1)
+ whenever(freenetInterface.insertDirectory(eq(insertUri), any<HashMap<String, Any>>(), eq("index.html"))).thenAnswer {
+ soneInserter.stop()
+ throw SoneException(Exception())
+ }
+ soneInserter.serviceRun()
+ val histogram = metricRegistry.histogram("sone.insert.duration")
+ assertThat(histogram.count, equalTo(0L))
+ val meter = metricRegistry.meter("sone.insert.errors")
+ assertThat(meter.count, equalTo(1L))
+ }
+