Search in sources :

Example 21 with UUID

use of java.util.UUID in project hadoop by apache.

the class ClientId method getClientId.

/**
   * Return clientId as byte[]
   */
public static byte[] getClientId() {
    UUID uuid = UUID.randomUUID();
    ByteBuffer buf = ByteBuffer.wrap(new byte[BYTE_LENGTH]);
    buf.putLong(uuid.getMostSignificantBits());
    buf.putLong(uuid.getLeastSignificantBits());
    return buf.array();
}
Also used : UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer)

Example 22 with UUID

use of java.util.UUID in project flink by apache.

the class FlinkUntypedActorTest method testThrowingExceptionWhenReceivingNonWrappedRequiresLeaderSessionIDMessage.

/**
	 * Tests that an exception is thrown, when the FlinkUntypedActore receives a message which
	 * extends {@link RequiresLeaderSessionID} and is not wrapped in a LeaderSessionMessage.
	 */
@Test
public void testThrowingExceptionWhenReceivingNonWrappedRequiresLeaderSessionIDMessage() {
    final UUID leaderSessionID = UUID.randomUUID();
    TestActorRef<PlainFlinkUntypedActor> actor = null;
    try {
        final Props props = Props.create(PlainFlinkUntypedActor.class, leaderSessionID);
        actor = TestActorRef.create(actorSystem, props);
        actor.receive(new JobManagerMessages.LeaderSessionMessage(leaderSessionID, 1));
        try {
            actor.receive(new PlainRequiresLeaderSessionID());
            fail("Expected an exception to be thrown, because a RequiresLeaderSessionID" + "message was sent without being wrapped in LeaderSessionMessage.");
        } catch (Exception e) {
            assertEquals("Received a message PlainRequiresLeaderSessionID " + "without a leader session ID, even though the message requires a " + "leader session ID.", e.getMessage());
        }
    } finally {
        stopActor(actor);
    }
}
Also used : JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) UUID(java.util.UUID) Props(akka.actor.Props) Test(org.junit.Test)

Example 23 with UUID

use of java.util.UUID in project flink by apache.

the class ZooKeeperLeaderElectionService method nodeChanged.

@Override
public void nodeChanged() throws Exception {
    try {
        // leaderSessionID is null if the leader contender has not yet confirmed the session ID
        if (leaderLatch.hasLeadership()) {
            synchronized (lock) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Leader node changed while {} is the leader with session ID {}.", leaderContender.getAddress(), confirmedLeaderSessionID);
                }
                if (confirmedLeaderSessionID != null) {
                    ChildData childData = cache.getCurrentData();
                    if (childData == null) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Writing leader information into empty node by {}.", leaderContender.getAddress());
                        }
                        writeLeaderInformation(confirmedLeaderSessionID);
                    } else {
                        byte[] data = childData.getData();
                        if (data == null || data.length == 0) {
                            // the data field seems to be empty, rewrite information
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Writing leader information into node with empty data field by {}.", leaderContender.getAddress());
                            }
                            writeLeaderInformation(confirmedLeaderSessionID);
                        } else {
                            ByteArrayInputStream bais = new ByteArrayInputStream(data);
                            ObjectInputStream ois = new ObjectInputStream(bais);
                            String leaderAddress = ois.readUTF();
                            UUID leaderSessionID = (UUID) ois.readObject();
                            if (!leaderAddress.equals(this.leaderContender.getAddress()) || (leaderSessionID == null || !leaderSessionID.equals(confirmedLeaderSessionID))) {
                                // the data field does not correspond to the expected leader information
                                if (LOG.isDebugEnabled()) {
                                    LOG.debug("Correcting leader information by {}.", leaderContender.getAddress());
                                }
                                writeLeaderInformation(confirmedLeaderSessionID);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        leaderContender.handleError(new Exception("Could not handle node changed event.", e));
        throw e;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ChildData(org.apache.curator.framework.recipes.cache.ChildData) UUID(java.util.UUID) KeeperException(org.apache.zookeeper.KeeperException) ObjectInputStream(java.io.ObjectInputStream)

Example 24 with UUID

use of java.util.UUID in project flink by apache.

the class SingleLeaderElectionServiceTest method testShutdown.

@Test
public void testShutdown() throws Exception {
    final UUID uuid = UUID.randomUUID();
    final SingleLeaderElectionService service = new SingleLeaderElectionService(executor, uuid);
    // create a leader contender and let it grab leadership
    final LeaderContender contender = mockContender(service);
    service.start(contender);
    verify(contender, times(1)).grantLeadership(uuid);
    // some leader listeners
    final LeaderRetrievalListener listener1 = mock(LeaderRetrievalListener.class);
    final LeaderRetrievalListener listener2 = mock(LeaderRetrievalListener.class);
    LeaderRetrievalService listenerService1 = service.createLeaderRetrievalService();
    LeaderRetrievalService listenerService2 = service.createLeaderRetrievalService();
    listenerService1.start(listener1);
    listenerService2.start(listener2);
    // one listener stops
    listenerService1.stop();
    // shut down the service
    service.shutdown();
    // the leader contender and running listener should get error notifications
    verify(contender, times(1)).handleError(any(Exception.class));
    verify(listener2, times(1)).handleError(any(Exception.class));
    // the stopped listener gets no notification
    verify(listener1, times(0)).handleError(any(Exception.class));
    // should not be possible to start again after shutdown
    try {
        service.start(contender);
        fail("should fail with an exception");
    } catch (IllegalStateException e) {
    // expected
    }
    // no additional leadership grant
    verify(contender, times(1)).grantLeadership(any(UUID.class));
}
Also used : LeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalService) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) LeaderRetrievalListener(org.apache.flink.runtime.leaderretrieval.LeaderRetrievalListener) UUID(java.util.UUID) Test(org.junit.Test)

Example 25 with UUID

use of java.util.UUID in project flink by apache.

the class SingleLeaderElectionServiceTest method mockContender.

private static LeaderContender mockContender(final LeaderElectionService service, final String address) {
    LeaderContender mockContender = mock(LeaderContender.class);
    when(mockContender.getAddress()).thenReturn(address);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            final UUID uuid = (UUID) invocation.getArguments()[0];
            service.confirmLeaderSessionID(uuid);
            return null;
        }
    }).when(mockContender).grantLeadership(any(UUID.class));
    return mockContender;
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) LeaderContender(org.apache.flink.runtime.leaderelection.LeaderContender) UUID(java.util.UUID)

Aggregations

UUID (java.util.UUID)2250 Test (org.junit.Test)441 Test (org.testng.annotations.Test)307 ArrayList (java.util.ArrayList)250 HashMap (java.util.HashMap)224 ClusterNode (org.apache.ignite.cluster.ClusterNode)154 LocalDate (org.joda.time.LocalDate)143 BigDecimal (java.math.BigDecimal)142 Map (java.util.Map)136 List (java.util.List)105 Invoice (org.killbill.billing.invoice.api.Invoice)105 Ignite (org.apache.ignite.Ignite)103 DateTime (org.joda.time.DateTime)94 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)93 CountDownLatch (java.util.concurrent.CountDownLatch)92 HashSet (java.util.HashSet)90 InvoiceItem (org.killbill.billing.invoice.api.InvoiceItem)70 IOException (java.io.IOException)66 Event (org.apache.ignite.events.Event)66 LinkedList (java.util.LinkedList)65