Ray Milkey | 8526700 | 2016-11-16 11:06:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Jonathan Hart | 679d24d | 2016-05-13 13:29:53 -0700 | [diff] [blame] | 16 | package org.onosproject.store.serializers; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.util.KryoNamespace; |
| 20 | |
| 21 | import static org.junit.Assert.assertTrue; |
| 22 | |
| 23 | /** |
| 24 | * Tests pre-defined Kryo namespaces to catch basic errors such as someone |
| 25 | * adding too many registrations which may flow into another namespace. |
| 26 | */ |
| 27 | public class KryoNamespacesTest { |
| 28 | |
| 29 | /** |
| 30 | * Verifies that the BASIC namespace has not exceeded its allocated size. |
| 31 | */ |
| 32 | @Test |
| 33 | public void basicNamespaceSizeTest() { |
| 34 | testNamespaceSize(KryoNamespaces.BASIC, KryoNamespaces.BASIC_MAX_SIZE); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Verifies that the MISC namespace has not exceeded its allocated size. |
| 39 | */ |
| 40 | @Test |
| 41 | public void miscNamespaceSizeTest() { |
| 42 | testNamespaceSize(KryoNamespaces.MISC, KryoNamespaces.MISC_MAX_SIZE); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Verifies that the API namespace has not exceeded its allocated size. |
| 47 | */ |
| 48 | @Test |
| 49 | public void apiNamespaceSizeTest() { |
| 50 | testNamespaceSize(KryoNamespaces.API, KryoNamespaces.API_MAX_SIZE); |
| 51 | } |
| 52 | |
| 53 | private void testNamespaceSize(KryoNamespace namespace, int maxSize) { |
| 54 | assertTrue("Kryo namespace has exceeded its allocated size", |
| 55 | namespace.size() < maxSize); |
| 56 | } |
| 57 | } |