Search in sources :

Example 1 with LeaderEventPublisher

use of org.springframework.integration.leader.event.LeaderEventPublisher 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());
}
Also used : AbstractLeaderEvent(org.springframework.integration.leader.event.AbstractLeaderEvent) LeaderInitiator(org.springframework.integration.zookeeper.leader.LeaderInitiator) OnGrantedEvent(org.springframework.integration.leader.event.OnGrantedEvent) LeaderEventPublisher(org.springframework.integration.leader.event.LeaderEventPublisher) DefaultLeaderEventPublisher(org.springframework.integration.leader.event.DefaultLeaderEventPublisher) DefaultCandidate(org.springframework.integration.leader.DefaultCandidate) OnRevokedEvent(org.springframework.integration.leader.event.OnRevokedEvent) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 DefaultCandidate (org.springframework.integration.leader.DefaultCandidate)1 AbstractLeaderEvent (org.springframework.integration.leader.event.AbstractLeaderEvent)1 DefaultLeaderEventPublisher (org.springframework.integration.leader.event.DefaultLeaderEventPublisher)1 LeaderEventPublisher (org.springframework.integration.leader.event.LeaderEventPublisher)1 OnGrantedEvent (org.springframework.integration.leader.event.OnGrantedEvent)1 OnRevokedEvent (org.springframework.integration.leader.event.OnRevokedEvent)1 LeaderInitiator (org.springframework.integration.zookeeper.leader.LeaderInitiator)1