Jonathan Hart | 679d24d | 2016-05-13 13:29:53 -0700 | [diff] [blame^] | 1 | package org.onosproject.store.serializers; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | import org.onlab.util.KryoNamespace; |
| 5 | |
| 6 | import static org.junit.Assert.assertTrue; |
| 7 | |
| 8 | /** |
| 9 | * Tests pre-defined Kryo namespaces to catch basic errors such as someone |
| 10 | * adding too many registrations which may flow into another namespace. |
| 11 | */ |
| 12 | public class KryoNamespacesTest { |
| 13 | |
| 14 | /** |
| 15 | * Verifies that the BASIC namespace has not exceeded its allocated size. |
| 16 | */ |
| 17 | @Test |
| 18 | public void basicNamespaceSizeTest() { |
| 19 | testNamespaceSize(KryoNamespaces.BASIC, KryoNamespaces.BASIC_MAX_SIZE); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Verifies that the MISC namespace has not exceeded its allocated size. |
| 24 | */ |
| 25 | @Test |
| 26 | public void miscNamespaceSizeTest() { |
| 27 | testNamespaceSize(KryoNamespaces.MISC, KryoNamespaces.MISC_MAX_SIZE); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Verifies that the API namespace has not exceeded its allocated size. |
| 32 | */ |
| 33 | @Test |
| 34 | public void apiNamespaceSizeTest() { |
| 35 | testNamespaceSize(KryoNamespaces.API, KryoNamespaces.API_MAX_SIZE); |
| 36 | } |
| 37 | |
| 38 | private void testNamespaceSize(KryoNamespace namespace, int maxSize) { |
| 39 | assertTrue("Kryo namespace has exceeded its allocated size", |
| 40 | namespace.size() < maxSize); |
| 41 | } |
| 42 | } |