use of org.springframework.integration.zookeeper.leader.LeaderInitiator in project spring-integration by spring-projects.
the class LeaderInitiatorFactoryBean method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
if (this.leaderInitiator == null) {
this.leaderInitiator = new LeaderInitiator(this.client, this.candidate, this.path);
this.leaderInitiator.setPhase(this.phase);
this.leaderInitiator.setAutoStartup(this.autoStartup);
if (this.leaderEventPublisher != null) {
this.leaderInitiator.setLeaderEventPublisher(this.leaderEventPublisher);
} else if (this.applicationEventPublisher != null) {
this.leaderInitiator.setLeaderEventPublisher(new DefaultLeaderEventPublisher(this.applicationEventPublisher));
}
}
}
use of org.springframework.integration.zookeeper.leader.LeaderInitiator in project spring-integration by spring-projects.
the class ZookeeperLeaderTests method testLeader.
@Test
public void testLeader() throws Exception {
assertFalse(this.adapter.isRunning());
LeaderEventPublisher publisher = publisher();
DefaultCandidate candidate1 = new DefaultCandidate("foo", "sitest");
LeaderInitiator initiator1 = new LeaderInitiator(this.client, candidate1, "/sitest");
initiator1.setLeaderEventPublisher(publisher);
initiator1.start();
DefaultCandidate candidate2 = new DefaultCandidate("bar", "sitest");
LeaderInitiator initiator2 = new LeaderInitiator(this.client, candidate2, "/sitest");
initiator2.setLeaderEventPublisher(publisher);
initiator2.start();
AbstractLeaderEvent event = this.events.poll(30, TimeUnit.SECONDS);
assertNotNull(event);
assertThat(event, instanceOf(OnGrantedEvent.class));
assertTrue(this.adapter.isRunning());
event.getContext().yield();
event = this.events.poll(30, TimeUnit.SECONDS);
assertNotNull(event);
assertThat(event, instanceOf(OnRevokedEvent.class));
assertFalse(this.adapter.isRunning());
this.yieldBarrier.countDown();
event = this.events.poll(30, TimeUnit.SECONDS);
assertNotNull(event);
assertThat(event, instanceOf(OnGrantedEvent.class));
assertTrue(this.adapter.isRunning());
initiator1.stop();
initiator2.stop();
event = this.events.poll(30, TimeUnit.SECONDS);
assertNotNull(event);
assertThat(event, instanceOf(OnRevokedEvent.class));
assertFalse(this.adapter.isRunning());
}
use of org.springframework.integration.zookeeper.leader.LeaderInitiator in project spring-integration by spring-projects.
the class LeaderInitiatorFactoryBeanTests method testExceptionFromEvent.
@Test
public void testExceptionFromEvent() throws Exception {
CountDownLatch onGranted = new CountDownLatch(1);
LeaderInitiator initiator = new LeaderInitiator(client, new DefaultCandidate());
initiator.setLeaderEventPublisher(new DefaultLeaderEventPublisher() {
@Override
public void publishOnGranted(Object source, Context context, String role) {
try {
throw new RuntimeException("intentional");
} finally {
onGranted.countDown();
}
}
});
initiator.start();
assertTrue(onGranted.await(10, TimeUnit.SECONDS));
assertTrue(initiator.getContext().isLeader());
initiator.stop();
}
Aggregations