This project has retired. For details please refer to its Attic page.
TestGiraphConfiguration xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  package org.apache.giraph.conf;
20  
21  import org.junit.Test;
22  
23  import static org.apache.giraph.conf.ClassConfOption.getClassesOfType;
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.fail;
26  
27  public class TestGiraphConfiguration {
28    public interface If { }
29    public class A implements If { }
30    public class B implements If { }
31    public class C implements If { }
32  
33    @Test
34    public void testSetClasses() {
35      GiraphConfiguration conf = new GiraphConfiguration();
36      conf.setClasses("foo", If.class, A.class, B.class);
37      Class<?>[] klasses = conf.getClasses("foo");
38      assertEquals(2, klasses.length);
39      assertEquals(A.class, klasses[0]);
40      assertEquals(B.class, klasses[1]);
41  
42      try {
43        conf.setClasses("foo", A.class, B.class);
44        fail();
45      } catch (RuntimeException e) {
46        assertEquals(2, conf.getClasses("foo").length);
47      }
48  
49      Class<? extends If>[] klasses2 = getClassesOfType(conf, "foo", If.class);
50      assertEquals(2, klasses2.length);
51      assertEquals(A.class, klasses2[0]);
52      assertEquals(B.class, klasses2[1]);
53    }
54  
55    @Test
56    public void testAddToClasses() {
57      GiraphConfiguration conf = new GiraphConfiguration();
58  
59      conf.setClasses("foo", If.class, A.class, B.class);
60      ClassConfOption.addToClasses(conf, "foo", C.class, If.class);
61      Class<?>[] klasses = conf.getClasses("foo");
62      assertEquals(3, klasses.length);
63      assertEquals(A.class, klasses[0]);
64      assertEquals(B.class, klasses[1]);
65      assertEquals(C.class, klasses[2]);
66  
67      ClassConfOption.addToClasses(conf, "bar", B.class, If.class);
68      klasses = conf.getClasses("bar");
69      assertEquals(1, klasses.length);
70      assertEquals(B.class, klasses[0]);
71    }
72  }