View Javadoc

1   package org.apache.helix;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.helix.ZNRecordBucketizer;
23  import org.testng.Assert;
24  import org.testng.annotations.Test;
25  
26  
27  public class TestZNRecordBucketizer
28  {
29    @Test
30    public void testZNRecordBucketizer()
31    {
32      final int bucketSize = 3;
33      ZNRecordBucketizer bucketizer = new ZNRecordBucketizer(bucketSize);
34      String[] partitionNames =
35          { "TestDB_0", "TestDB_1", "TestDB_2", "TestDB_3", "TestDB_4" };
36      for (int i = 0; i < partitionNames.length; i++)
37      {
38        String partitionName = partitionNames[i];
39        String bucketName = bucketizer.getBucketName(partitionName);
40        int startBucketNb = i / bucketSize * bucketSize;
41        int endBucketNb = startBucketNb + bucketSize - 1;
42        String expectBucketName = "TestDB_p" + startBucketNb + "-p" + endBucketNb;
43        System.out.println("Expect: " + expectBucketName + ", actual: " + bucketName);
44        Assert.assertEquals(expectBucketName, bucketName);
45        
46      }
47      
48  //    ZNRecord record = new ZNRecord("TestDB");
49  //    record.setSimpleField("key0", "value0");
50  //    record.setSimpleField("key1", "value1");
51  //    record.setListField("TestDB_0", Arrays.asList("localhost_00", "localhost_01"));
52  //    record.setListField("TestDB_1", Arrays.asList("localhost_10", "localhost_11"));
53  //    record.setListField("TestDB_2", Arrays.asList("localhost_20", "localhost_21"));
54  //    record.setListField("TestDB_3", Arrays.asList("localhost_30", "localhost_31"));
55  //    record.setListField("TestDB_4", Arrays.asList("localhost_40", "localhost_41"));
56  //    
57  //    System.out.println(bucketizer.bucketize(record));
58      
59    }
60  }