@Test public void fireAnnouncementStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onAnnouncementStart(version); listenerSupport.listeners().fireAnnouncementStart(readState); Mockito.verify(listener).onAnnouncementStart(version); } }
@Test public void fireCycleStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onCycleStart(version); listenerSupport.listeners().fireCycleStart(version); Mockito.verify(listener).onCycleStart(version); }
@Test public void fireIntegrityCheckStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onIntegrityCheckStart(version); listenerSupport.listeners().fireIntegrityCheckStart(readState); Mockito.verify(listener).onIntegrityCheckStart(version); }
Status.StageBuilder populateStatus = listeners.firePopulateStart(toVersion); try (CloseableWriteState writeState = new CloseableWriteState(toVersion, objectMapper, readStates.current())) { throw th; } finally { listeners.firePopulateComplete(populateStatus); listeners.fireNoDelta(toVersion);
Status.StageWithStateBuilder status = listeners.fireIntegrityCheckStart(readStates.pending()); try { ReadStateHelper result = readStates; throw th; } finally { listeners.fireIntegrityCheckComplete(status);
s.fireCycleStart(1); s.fireCycleComplete(new Status.StageWithStateBuilder()); s.fireCycleStart(1); s.fireCycleComplete(new Status.StageWithStateBuilder());
s.fireCycleStart(1); s.fireCycleComplete(new Status.StageWithStateBuilder()); s.fireCycleStart(1); s.fireCycleComplete(new Status.StageWithStateBuilder());
Status.RestoreStageBuilder status = localListeners.fireProducerRestoreStart(versionDesired); try { if (versionDesired != HollowConstants.VERSION_NONE) { throw th; } finally { localListeners.fireProducerRestoreComplete(status);
void publish(ListenerSupport.Listeners listeners, long toVersion, Artifacts artifacts) throws IOException { Status.StageBuilder psb = listeners.firePublishStart(toVersion); try { stageBlob(toVersion, artifacts, Blob.Type.SNAPSHOT); throw throwable; } finally { listeners.firePublishComplete(psb);
/** * Initializes the data model for the given classes. * <p> * Data model initialization is required prior to {@link #restore(long, HollowConsumer.BlobRetriever) restoring} * the producer. * This ensures that restoration can correctly compare the producer's current data model * with the data model of the restored data state and manage any differences in those models * (such as not restoring state for any types in the restoring data model not present in the * producer's current data model). * <p> * After initialization a data model initialization event will be emitted * to all registered data model initialization * {@link com.netflix.hollow.api.producer.listener.DataModelInitializationListener listeners}. * * @param classes the data model classes * @throws IllegalArgumentException if {@code classes} is empty * @see #restore(long, HollowConsumer.BlobRetriever) */ public void initializeDataModel(Class<?>... classes) { Objects.requireNonNull(classes); if (classes.length == 0) { throw new IllegalArgumentException("classes is empty"); } long start = currentTimeMillis(); for (Class<?> c : classes) { objectMapper.initializeTypeState(c); } listeners.listeners().fireProducerInit(currentTimeMillis() - start); isInitialized = true; }
localListeners.fireCycleSkipped(CycleListener.CycleSkipReason.NOT_PRIMARY_PRODUCER); return lastSuccessfulCycle; localListeners.fireNewDeltaChain(toVersion); Status.StageWithStateBuilder cycleStatus = localListeners.fireCycleStart(toVersion); localListeners.fireCycleComplete(cycleStatus); metrics.updateCycleMetrics(cycleStatus.build(), cycleStatus.readState, cycleStatus.version); if (metricsCollector != null) {
/** * Initializes the producer data model for the given schemas. * <p> * Data model initialization is required prior to {@link #restore(long, HollowConsumer.BlobRetriever) restoring} * the producer. * This ensures that restoration can correctly compare the producer's current data model * with the data model of the restored data state and manage any differences in those models * (such as not restoring state for any types in the restoring data model not present in the * producer's current data model). * <p> * After initialization a data model initialization event will be emitted * to all registered data model initialization * {@link com.netflix.hollow.api.producer.listener.DataModelInitializationListener listeners}. * * @param schemas the data model classes * @throws IllegalArgumentException if {@code schemas} is empty * @see #restore(long, HollowConsumer.BlobRetriever) */ public void initializeDataModel(HollowSchema... schemas) { Objects.requireNonNull(schemas); if (schemas.length == 0) { throw new IllegalArgumentException("classes is empty"); } long start = currentTimeMillis(); HollowWriteStateCreator.populateStateEngineWithTypeWriteStates(getWriteEngine(), Arrays.asList(schemas)); listeners.listeners().fireProducerInit(currentTimeMillis() - start); isInitialized = true; }
private void validate(ListenerSupport.Listeners listeners, HollowProducer.ReadState readState) { Status.StageWithStateBuilder psb = listeners.fireValidationStart(readState); ValidationStatus status = null; try { // Stream over the concatenation of the old and new validators List<ValidationResult> results = listeners.getListeners(ValidatorListener.class) .map(v -> { try { return v.onValidate(readState); } catch (RuntimeException e) { return ValidationResult.from(v).error(e); } }) .collect(toList()); status = new ValidationStatus(results); if (!status.passed()) { ValidationStatusException e = new ValidationStatusException( status, "One or more validations failed. Please check individual failures."); psb.fail(e); throw e; } psb.success(); } finally { listeners.fireValidationComplete(psb, status); } }
@Test public void fireProducerRestoreStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onProducerRestoreStart(version); Status.RestoreStageBuilder b = new Status.RestoreStageBuilder(); listenerSupport.listeners().fireProducerRestoreComplete(b); ArgumentCaptor<Status> status = ArgumentCaptor.forClass( Status.class); ArgumentCaptor<Long> desired = ArgumentCaptor.forClass( long.class); ArgumentCaptor<Long> reached = ArgumentCaptor.forClass( long.class); ArgumentCaptor<Duration> elapsed = ArgumentCaptor.forClass( Duration.class); Mockito.verify(listener).onProducerRestoreComplete(status.capture(), desired.capture(), reached.capture(), elapsed.capture()); Assert.assertNotNull(status.getValue()); Assert.assertNotNull(elapsed.getValue()); }
private void announce(ListenerSupport.Listeners listeners, HollowProducer.ReadState readState) { if (announcer != null) { Status.StageWithStateBuilder status = listeners.fireAnnouncementStart(readState); try { announcer.announce(readState.getVersion()); status.success(); } catch (Throwable th) { status.fail(th); throw th; } finally { listeners.fireAnnouncementComplete(status); } } }
@Test public void firePublishStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onPublishStart(version); listenerSupport.listeners().firePublishStart(version); Mockito.verify(listener).onPublishStart(version); }
@Test public void firePopulateStartDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onPopulateStart(version); listenerSupport.listeners().firePopulateStart(version); Mockito.verify(listener).onPopulateStart(version); }
@Test public void fireNewDeltaChainDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onNewDeltaChain(version); listenerSupport.listeners().fireNewDeltaChain(version); Mockito.verify(listener).onNewDeltaChain(version); }
@Test public void testFireValidationStartDontStopWhenOneFails2() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(validationStatusListener).onValidationStatusStart(version); listenerSupport.listeners().fireValidationStart(readState); Mockito.verify(listener).onValidationStart(version); Mockito.verify(validationStatusListener).onValidationStatusStart(version); Mockito.verify(producerAndValidationStatusListener).onValidationStart(version); }
@Test public void fireProducerInitDontStopWhenOneFails() { long version = 31337; HollowProducer.ReadState readState = Mockito.mock(HollowProducer.ReadState.class); Mockito.when(readState.getVersion()).thenReturn(version); Mockito.doThrow(RuntimeException.class).when(listener).onProducerInit(1L, MILLISECONDS); listenerSupport.listeners().fireProducerInit(1L); Mockito.verify(listener).onProducerInit(Duration.ofMillis(1L)); }