BUG 4589 : Handle writing and reading large strings
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / datastore / node / utils / stream / ValueTypesTest.java
1 /*
2  * Copyright (c) 2015 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
9 package org.opendaylight.controller.cluster.datastore.node.utils.stream;
10
11 import static org.junit.Assert.assertEquals;
12 import org.junit.Test;
13
14 public class ValueTypesTest {
15     @Test
16     public void testStringType(){
17         assertEquals(ValueTypes.STRING_TYPE, ValueTypes.getSerializableType("foobar"));
18         final String largeString = largeString(ValueTypes.STRING_BYTES_LENGTH_THRESHOLD);
19         assertEquals(ValueTypes.STRING_BYTES_TYPE, ValueTypes.getSerializableType(largeString));
20     }
21
22     private String largeString(int minSize){
23         final int pow = (int) (Math.log(minSize * 2) / Math.log(2));
24         String s = "X";
25         for(int i=0;i<pow;i++){
26             StringBuilder b = new StringBuilder();
27             b.append(s).append(s);
28             s = b.toString();
29         }
30         return s;
31     }
32
33 }