Merge "BUG-2459: Default to byte-aligned encoding"
[controller.git] / opendaylight / md-sal / benchmark-data-store / src / main / java / org / opendaylight / controller / md / sal / dom / store / benchmark / InMemoryBrokerWriteTransactionBenchmark.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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.md.sal.dom.store.benchmark;
9
10 import com.google.common.collect.ImmutableMap;
11 import com.google.common.util.concurrent.ListeningExecutorService;
12 import com.google.common.util.concurrent.MoreExecutors;
13 import java.util.Map;
14 import java.util.concurrent.Executors;
15 import java.util.concurrent.ThreadPoolExecutor;
16 import java.util.concurrent.TimeUnit;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker;
19 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
21 import org.openjdk.jmh.annotations.BenchmarkMode;
22 import org.openjdk.jmh.annotations.Fork;
23 import org.openjdk.jmh.annotations.Level;
24 import org.openjdk.jmh.annotations.Mode;
25 import org.openjdk.jmh.annotations.OutputTimeUnit;
26 import org.openjdk.jmh.annotations.Scope;
27 import org.openjdk.jmh.annotations.Setup;
28 import org.openjdk.jmh.annotations.State;
29
30 @State(Scope.Thread)
31 @BenchmarkMode(Mode.AverageTime)
32 @OutputTimeUnit(TimeUnit.MILLISECONDS)
33 @Fork(1)
34 public class InMemoryBrokerWriteTransactionBenchmark extends AbstractInMemoryBrokerWriteTransactionBenchmark {
35     private ListeningExecutorService executor;
36
37     @Setup(Level.Trial)
38     @Override
39     public void setUp() throws Exception {
40         ListeningExecutorService dsExec = MoreExecutors.sameThreadExecutor();
41         executor = MoreExecutors.listeningDecorator(
42             MoreExecutors.getExitingExecutorService((ThreadPoolExecutor)Executors.newFixedThreadPool(1), 1L, TimeUnit.SECONDS));
43
44         InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", dsExec);
45         InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", dsExec);
46         Map<LogicalDatastoreType, DOMStore> datastores = ImmutableMap.of(
47             LogicalDatastoreType.OPERATIONAL, (DOMStore)operStore,
48             LogicalDatastoreType.CONFIGURATION, configStore);
49
50         domBroker = new SerializedDOMDataBroker(datastores, executor);
51         schemaContext = BenchmarkModel.createTestContext();
52         configStore.onGlobalContextUpdated(schemaContext);
53         operStore.onGlobalContextUpdated(schemaContext);
54         initTestNode();
55     }
56
57     @Override
58     public void tearDown() {
59         domBroker.close();
60         executor.shutdown();
61     }
62 }

©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.