/** * Invoke this method to alter runCycle behavior. If this Producer is not primary, runCycle is a no-op. Note that by default, * SingleProducerEnforcer is instantiated as BasicSingleProducerEnforcer, which is initialized to return true for isPrimary() * * @param doEnable true if enable primary producer, if false * @return true if the intended action was successful */ public boolean enablePrimaryProducer(boolean doEnable) { if (doEnable) { singleProducerEnforcer.enable(); } else { singleProducerEnforcer.disable(); } return (singleProducerEnforcer.isPrimary() == doEnable); }
@Test public void testCycleStartEnd() { Mockito.when(singleProducerEnforcer.isPrimary()).thenReturn(true); this.producer.runCycle(Mockito.mock(HollowProducer.Populator.class)); Mockito.verify(listener).onCycleStart(ArgumentMatchers.anyLong()); Mockito.verify(listener).onCycleComplete( Mockito.any(HollowProducerListener.ProducerStatus.class), ArgumentMatchers.anyLong(), Mockito.any(TimeUnit.class)); } }
@Test public void testCycleSkip() { Mockito.when(singleProducerEnforcer.isPrimary()).thenReturn(false); this.producer.runCycle(null); Mockito.verify(listener).onCycleSkip( HollowProducerListener.CycleSkipReason.NOT_PRIMARY_PRODUCER); Mockito.verify(listener, Mockito.never()).onCycleStart( ArgumentMatchers.anyLong()); }
ListenerSupport.Listeners localListeners = listeners.listeners(); if (!singleProducerEnforcer.isPrimary()) {