Use java.lang.ref.Cleaner for ClientBackedTransaction
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedTransactionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.databroker;
9
10 import static org.mockito.Mockito.times;
11 import static org.mockito.Mockito.verify;
12
13 import org.junit.Test;
14 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
15 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
17 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
18 import org.opendaylight.controller.cluster.access.concepts.MemberName;
19 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
20 import org.opendaylight.controller.cluster.databroker.actors.dds.AbstractClientHandle;
21
22 public abstract class ClientBackedTransactionTest<T extends ClientBackedTransaction<?>> {
23     private static FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(
24             MemberName.forName("member"), FrontendType.forName("frontend"));
25     protected static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
26
27     private static LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 0);
28     protected static final TransactionIdentifier TRANSACTION_ID = new TransactionIdentifier(HISTORY_ID, 0);
29
30     abstract T object();
31
32     @Test
33     public void testClose() {
34         final AbstractClientHandle<?> delegate = object().delegate();
35         object().close();
36         // Called twice because of immediate cleaning
37         verify(delegate, times(2)).abort();
38     }
39 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.