@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()); }
@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); }
@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()); }
@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()); } }
@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()); }