2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.protocol.pcep.pcc.mock;
11 import com.google.common.collect.ImmutableList;
12 import com.google.common.util.concurrent.Uninterruptibles;
13 import java.util.ArrayList;
14 import java.util.List;
15 import java.util.concurrent.CountDownLatch;
16 import java.util.concurrent.TimeUnit;
17 import javax.annotation.concurrent.GuardedBy;
18 import org.junit.Assert;
19 import org.opendaylight.protocol.pcep.PCEPSession;
20 import org.opendaylight.protocol.pcep.PCEPSessionListener;
21 import org.opendaylight.protocol.pcep.PCEPTerminationReason;
22 import org.opendaylight.protocol.util.CheckUtil.ListenerCheck;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class TestingSessionListener implements PCEPSessionListener, ListenerCheck {
29 private static final Logger LOG = LoggerFactory.getLogger(TestingSessionListener.class);
30 private final CountDownLatch sessionLatch = new CountDownLatch(1);
33 private final List<Message> messages = new ArrayList<>();
35 private boolean up = false;
36 private PCEPSession session = null;
39 public synchronized void onMessage(final PCEPSession session, final Message message) {
40 LOG.debug("Received message: {}", message);
41 this.messages.add(message);
45 public void onSessionUp(final PCEPSession session) {
46 LOG.debug("Session up.");
48 this.session = session;
49 this.sessionLatch.countDown();
54 public void onSessionDown(final PCEPSession session, final Exception exception) {
55 LOG.debug("Session down. Cause : {} ", exception, exception);
61 public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
62 LOG.debug("Session terminated. Cause : {}", cause);
65 synchronized List<Message> messages() {
66 return ImmutableList.copyOf(this.messages);
73 public PCEPSession getSession() {
74 Assert.assertEquals("Session up", true,
75 Uninterruptibles.awaitUninterruptibly(this.sessionLatch, 10, TimeUnit.SECONDS));
80 public synchronized int getListMessageSize() {
81 return this.messages.size();