* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.md.sal.binding.impl.test;
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
TreeComplexUsesAugment.class);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
}
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
TOP_PATH.child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
}
import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
new ListViaUsesKey("list key modified");
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class),
BindingReflections.getModuleInfo(TreeLeafOnlyUsesAugment.class));
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.md.sal.binding.impl.test;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
+import java.util.Set;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
}
private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Root.class));
}
listener.verify();
}
- private boolean checkData(Root expected, Root actual) {
+ private static boolean checkData(final Root expected, final Root actual) {
if (actual == null) {
return false;
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.md.sal.binding.impl.test;
import static org.junit.Assert.assertEquals;
import com.google.common.util.concurrent.SettableFuture;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
}
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(
BindingReflections.getModuleInfo(TwoLevelList.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class)
import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
private static final Logger LOG = LoggerFactory.getLogger(ForwardedNotificationAdapterTest.class);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(TwoLevelListChanged.class));
}
private static final InstanceIdentifier<TopLevelList> TOP_BAR = TOP.child(TopLevelList.class, TOP_BAR_KEY);
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class));
}
barListener.verify();
}
- private Function<DataTreeModification<Top>, Boolean> topSubtreeModified(TopLevelList topFoo, TopLevelList topBar) {
+ private Function<DataTreeModification<Top>, Boolean> topSubtreeModified(final TopLevelList topFoo,
+ final TopLevelList topBar) {
return match(ModificationType.SUBTREE_MODIFIED, TOP,
(Function<Top, Boolean>) dataBefore -> Objects.equals(top(topFoo), dataBefore),
dataAfter -> {
*/
package org.opendaylight.controller.md.sal.binding.test;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import org.junit.Before;
import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-public abstract class AbstractSchemaAwareTest {
+public abstract class AbstractSchemaAwareTest {
+ private static final LoadingCache<ClassLoader, Set<YangModuleInfo>> MODULE_INFO_CACHE = CacheBuilder.newBuilder()
+ .weakKeys().weakValues().build(new CacheLoader<ClassLoader, Set<YangModuleInfo>>() {
+ @Override
+ public Set<YangModuleInfo> load(final ClassLoader key) {
+ return BindingReflections.loadModuleInfos(key);
+ }
+ });
+ private static final LoadingCache<Set<YangModuleInfo>, SchemaContext> SCHEMA_CONTEXT_CACHE =
+ CacheBuilder.newBuilder().weakValues().build(new CacheLoader<Set<YangModuleInfo>, SchemaContext>() {
+ @Override
+ public SchemaContext load(final Set<YangModuleInfo> key) {
+ final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
+ moduleContext.addModuleInfos(key);
+ return moduleContext.tryToCreateSchemaContext().get();
+ }
+ });
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
- return BindingReflections.loadModuleInfos();
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
+ return MODULE_INFO_CACHE.getUnchecked(Thread.currentThread().getContextClassLoader());
}
protected SchemaContext getSchemaContext() throws Exception {
- final Iterable<YangModuleInfo> moduleInfos = getModuleInfos();
- final ModuleInfoBackedContext moduleContext = ModuleInfoBackedContext.create();
- moduleContext.addModuleInfos(moduleInfos);
- return moduleContext.tryToCreateSchemaContext().get();
+ // ImmutableSet guarantees non-null
+ return SCHEMA_CONTEXT_CACHE.getUnchecked(ImmutableSet.copyOf(getModuleInfos()));
}
@Before
* it for each Test, and is thus faster.
*
* @author Michael Vorburger
+ * @deprecated This class is no longer useful, as {@link AbstractSchemaAwareTest#getSchemaContext()} provides effective
+ * caching.
*/
+@Deprecated
public class ConstantSchemaAbstractDataBrokerTest extends AbstractConcurrentDataBrokerTest {
public ConstantSchemaAbstractDataBrokerTest() {
* SchemaContext.
*
* @author Michael Vorburger
+ * @deprecated This class should not be used, as it pollutes the classpath.
*/
+@Deprecated
public final class SchemaContextSingleton {
private static SchemaContext staticSchemaContext;
- public static synchronized SchemaContext getSchemaContext(Supplier<SchemaContext> supplier) throws Exception {
+ public static synchronized SchemaContext getSchemaContext(final Supplier<SchemaContext> supplier) throws Exception {
if (staticSchemaContext == null) {
staticSchemaContext = supplier.get();
}
import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.Uninterruptibles;
import java.util.Collections;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
.withKey(LIST_VIA_USES_KEY).setName("john").build();
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-
package org.opendaylight.controller.sal.binding.test.bugfix;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
.build();
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(List11SimpleAugment.class));
}
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
import com.google.common.collect.ImmutableSet;
+import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.junit.Test;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
.builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).build();
@Override
- protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
+ protected Set<YangModuleInfo> getModuleInfos() throws Exception {
return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
}