2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.controller.cluster.access.client;
11 import java.util.concurrent.Executors;
12 import java.util.concurrent.ScheduledExecutorService;
13 import java.util.concurrent.TimeUnit;
14 import org.junit.After;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
19 public class InversibleLockTest {
21 private InversibleLock lock;
22 private ScheduledExecutorService executor;
26 lock = new InversibleLock();
27 executor = Executors.newScheduledThreadPool(1);
31 public void tearDown() {
32 executor.shutdownNow();
36 public void testWriteLockUnlock() {
37 final long stamp = lock.writeLock();
38 Assert.assertTrue(lock.validate(stamp));
39 executor.schedule(() -> lock.unlockWrite(stamp), 500, TimeUnit.MILLISECONDS);
41 lock.optimisticRead();
42 } catch (final InversibleLockException e) {
48 public void testLockAfterRead() {
49 final long readStamp = lock.optimisticRead();
51 Assert.assertFalse(lock.validate(readStamp));