/** * Closes any {@link StatArchiveWriter} currently in use by this handler. * */ public void close() throws GemFireException { synchronized (this) { if (archiver != null) { archiver.close(); } } }
private void handleArchiverException(GemFireException ex) { if (this.archiver.getSampleCount() > 0) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw, true)); logger.warn(LogMarker.STATISTICS_MARKER, "Statistic archiver shutting down because: {}", sw); } try { this.archiver.close(); } catch (GemFireException ignore) { if (this.archiver.getSampleCount() > 0) { logger.warn(LogMarker.STATISTICS_MARKER, "Statistic archiver shutdown failed because: {}", ignore.getMessage()); } } if (this.archiver.getSampleCount() == 0 && this.archiveId != -1) { // dec since we didn't use the file and close deleted it. this.archiveId--; } this.archiver = null; }
@Test public void shouldBeMockable() throws Exception { StatArchiveWriter mockStatArchiveWriter = mock(StatArchiveWriter.class); when(mockStatArchiveWriter.bytesWritten()).thenReturn(1L); mockStatArchiveWriter.close(); verify(mockStatArchiveWriter, times(1)).close(); assertThat(mockStatArchiveWriter.bytesWritten()).isEqualTo(1L); } }