congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
com.netflix.hollow.api.producer.enforcer
Code IndexAdd Tabnine to your IDE (free)

How to use com.netflix.hollow.api.producer.enforcer

Best Java code snippets using com.netflix.hollow.api.producer.enforcer (Showing top 16 results out of 315)

origin: Netflix/hollow

@Override
public void enable() {
  if (_isPrimary()) {
    return;
  }
  _enable();
}
origin: Netflix/hollow

@Override
public void force() {
  if (_isPrimary()) {
    return;
  }
  _force();
}
origin: Netflix/hollow

private void disableNow() {
  if (_isPrimary()) {
    _disable();
  }
  doStopUponCycleComplete = false;
  wasPrimary = false;
}
origin: Netflix/hollow

@Test
public void testEnabledDisabledCyle() {
  BasicSingleProducerEnforcer se = new BasicSingleProducerEnforcer();
  Assert.assertTrue(se.isPrimary());
  se.onCycleStart(1234L);
  se.onCycleComplete(null, 10L, TimeUnit.SECONDS);
  se.disable();
  Assert.assertFalse(se.isPrimary());
}
origin: Netflix/hollow

/**
 * 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);
}
origin: Netflix/hollow

@Test
public void testEnableDisable() {
  BasicSingleProducerEnforcer se = new BasicSingleProducerEnforcer();
  Assert.assertTrue(se.isPrimary());
  se.disable();
  Assert.assertFalse(se.isPrimary());
  se.enable();
  Assert.assertTrue(se.isPrimary());
}
origin: Netflix/hollow

@Test
public void testNotPrimaryProducerVersion() {
  BasicSingleProducerEnforcer enforcer = new BasicSingleProducerEnforcer();
  HollowProducer producer = HollowProducer.withPublisher(new FakeBlobPublisher())
      .withSingleProducerEnforcer(enforcer)
      .withAnnouncer(new HollowFilesystemAnnouncer(tmpFolder.toPath()))
      .build();
  producer.addListener(new FakeProducerListener());
  long v1 = producer.runCycle(ws -> {
    ws.add(1);
  });
  enforcer.disable();
  // Run cycle as not the primary producer
  long v2 = producer.runCycle(ws -> {
    ws.add(1);
  });
  // Run cycle as the primary producer
  enforcer.enable();
  long v3 = producer.runCycle(ws -> {
    ws.add(2);
  });
  Assert.assertEquals(v1, v2);
  Assert.assertTrue(v3 > v2);
}
origin: Netflix/hollow

  @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));
  }
}
origin: Netflix/hollow

@Deprecated
public HollowProducer(
    Publisher publisher,
    Announcer announcer) {
  this(new HollowFilesystemBlobStager(), publisher, announcer,
      Collections.emptyList(),
      new VersionMinterWithCounter(), null, 0,
      DEFAULT_TARGET_MAX_TYPE_SHARD_SIZE, null,
      new DummyBlobStorageCleaner(), new BasicSingleProducerEnforcer());
}
origin: Netflix/hollow

@Override
public void disable() {
  if (!hasCycleStarted) {
    disableNow();
  } else {
    doStopUponCycleComplete = true;
  }
}
origin: Netflix/hollow

@Override
public boolean isPrimary() {
  final boolean primary = _isPrimary();
  if (!primary) {
    if (wasPrimary) {
      logger.log(Level.WARNING, "SingleProducerEnforcer: lost primary producer status");
    }
  } else {
    wasPrimary = true;
  }
  return primary;
}
origin: Netflix/hollow

@Test
public void testMultiCycle() {
  BasicSingleProducerEnforcer se = new BasicSingleProducerEnforcer();
  for (int i = 0; i < 10; i++) {
    se.enable();
    Assert.assertTrue(se.isPrimary());
    se.onCycleStart(1234L);
    se.disable();
    Assert.assertTrue(se.isPrimary());
    se.onCycleComplete(null, 10L, TimeUnit.SECONDS);
    Assert.assertFalse(se.isPrimary());
  }
}
origin: Netflix/hollow

@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());
}
origin: Netflix/hollow

@Override
public void onCycleComplete(ProducerStatus status, long elapsed, TimeUnit unit) {
  hasCycleStarted = false;
  if (doStopUponCycleComplete) {
    disableNow();
  }
}
origin: Netflix/hollow

@Test
public void testTransitions() {
  BasicSingleProducerEnforcer se = new BasicSingleProducerEnforcer();
  Assert.assertTrue(se.isPrimary());
  se.onCycleStart(1234L);
  Assert.assertTrue(se.isPrimary());
  se.disable();
  Assert.assertTrue(se.isPrimary());
  se.onCycleComplete(null, 10L, TimeUnit.SECONDS);
  Assert.assertFalse(se.isPrimary());
  se.enable();
  Assert.assertTrue(se.isPrimary());
  se.onCycleStart(1235L);
  Assert.assertTrue(se.isPrimary());
  se.disable();
  Assert.assertTrue(se.isPrimary());
  se.onCycleComplete(null, 10L, TimeUnit.SECONDS);
  Assert.assertFalse(se.isPrimary());
}
origin: Netflix/hollow

ListenerSupport.Listeners localListeners = listeners.listeners();
if (!singleProducerEnforcer.isPrimary()) {
com.netflix.hollow.api.producer.enforcer

Most used classes

  • BasicSingleProducerEnforcer
  • SingleProducerEnforcer
  • AbstractSingleProducerEnforcer
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now