Added: 
incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java
URL: 
http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java?rev=1156404&view=auto
==============================================================================
--- incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java 
(added)
+++ incubator/giraph/trunk/src/test/java/org/apache/giraph/TestVertexTypes.java 
Wed Aug 10 23:57:25 2011
@@ -0,0 +1,205 @@
+/*
+ * Licensed to Yahoo! under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  Yahoo! licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.giraph.examples.GeneratedVertexInputFormat;
+import 
org.apache.giraph.examples.SimpleSuperstepVertex.SimpleSuperstepVertexInputFormat;
+import org.apache.giraph.graph.GiraphJob;
+import org.apache.giraph.graph.Vertex;
+import org.apache.giraph.graph.VertexCombiner;
+import org.apache.giraph.graph.VertexInputFormat;
+import org.apache.giraph.graph.GraphMapper;
+import org.apache.giraph.graph.VertexOutputFormat;
+import org.apache.giraph.lib.JsonBase64VertexInputFormat;
+import org.apache.giraph.lib.JsonBase64VertexOutputFormat;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.DoubleWritable;
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+
+public class TestVertexTypes
+    extends TestCase {
+
+    /**
+     * Matches the {@link GeneratedVertexInputFormat}
+     */
+    private static class GeneratedVertexMatch extends
+            Vertex<LongWritable, IntWritable, FloatWritable, FloatWritable> {
+        @Override
+        public void compute(Iterator<FloatWritable> msgIterator)
+                throws IOException {
+        }
+    }
+
+    /**
+     * Matches the {@link GeneratedVertexInputFormat}
+     */
+    private static class DerivedVertexMatch extends GeneratedVertexMatch {
+    }
+
+    /**
+     * Mismatches the {@link GeneratedVertexInputFormat}
+     */
+    private static class GeneratedVertexMismatch extends
+            Vertex<LongWritable, FloatWritable, FloatWritable, FloatWritable> {
+        @Override
+        public void compute(Iterator<FloatWritable> msgIterator)
+                throws IOException {
+        }
+    }
+
+    /**
+     * Matches the {@link GeneratedVertexMatch}
+     */
+    private static class GeneratedVertexMatchCombiner extends
+            VertexCombiner<LongWritable, FloatWritable> {
+
+        @Override
+        public FloatWritable combine(LongWritable vertexIndex,
+                                  List<FloatWritable> msgList)
+                throws IOException {
+            return null;
+        }
+    }
+
+    /**
+     * Mismatches the {@link GeneratedVertexMatch}
+     */
+    private static class GeneratedVertexMismatchCombiner extends
+            VertexCombiner<LongWritable, DoubleWritable> {
+
+        @Override
+        public DoubleWritable combine(LongWritable vertexIndex,
+                                      List<DoubleWritable> msgList)
+                throws IOException {
+            return null;
+        }
+    }
+
+    public void testMatchingType() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      GeneratedVertexMatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      SimpleSuperstepVertexInputFormat.class,
+                      VertexInputFormat.class);
+        conf.setClass(GiraphJob.VERTEX_COMBINER_CLASS,
+                      GeneratedVertexMatchCombiner.class,
+                      VertexCombiner.class);
+        mapper.determineClassTypes(conf);
+    }
+
+    public void testDerivedMatchingType() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      DerivedVertexMatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      SimpleSuperstepVertexInputFormat.class,
+                      VertexInputFormat.class);
+        mapper.determineClassTypes(conf);
+    }
+
+    public void testDerivedInputFormatType() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      DerivedVertexMatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      SimpleSuperstepVertexInputFormat.class,
+                      VertexInputFormat.class);
+        mapper.determineClassTypes(conf);
+    }
+
+    public void testMismatchingVertex() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      GeneratedVertexMismatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      SimpleSuperstepVertexInputFormat.class,
+                      VertexInputFormat.class);
+        try {
+            mapper.determineClassTypes(conf);
+            throw new RuntimeException(
+                "testMismatchingVertex: Should have caught an exception!");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+    public void testMismatchingCombiner() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      GeneratedVertexMatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      SimpleSuperstepVertexInputFormat.class,
+                      VertexInputFormat.class);
+        conf.setClass(GiraphJob.VERTEX_COMBINER_CLASS,
+                      GeneratedVertexMismatchCombiner.class,
+                      VertexCombiner.class);
+        try {
+            mapper.determineClassTypes(conf);
+            throw new RuntimeException(
+                "testMismatchingCombiner: Should have caught an exception!");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+
+    public void testJsonBase64FormatType() throws SecurityException,
+            NoSuchMethodException, NoSuchFieldException {
+        @SuppressWarnings("rawtypes")
+        GraphMapper<?, ?, ?, ?> mapper = new GraphMapper();
+        Configuration conf = new Configuration();
+        conf.setClass(GiraphJob.VERTEX_CLASS,
+                      GeneratedVertexMatch.class,
+                      Vertex.class);
+        conf.setClass(GiraphJob.VERTEX_INPUT_FORMAT_CLASS,
+                      JsonBase64VertexInputFormat.class,
+                      VertexInputFormat.class);
+        conf.setClass(GiraphJob.VERTEX_OUTPUT_FORMAT_CLASS,
+                      JsonBase64VertexOutputFormat.class,
+                      VertexOutputFormat.class);
+        mapper.determineClassTypes(conf);
+    }
+}

Added: 
incubator/giraph/trunk/src/test/java/org/apache/giraph/TestZooKeeperExt.java
URL: 
http://svn.apache.org/viewvc/incubator/giraph/trunk/src/test/java/org/apache/giraph/TestZooKeeperExt.java?rev=1156404&view=auto
==============================================================================
--- 
incubator/giraph/trunk/src/test/java/org/apache/giraph/TestZooKeeperExt.java 
(added)
+++ 
incubator/giraph/trunk/src/test/java/org/apache/giraph/TestZooKeeperExt.java 
Wed Aug 10 23:57:25 2011
@@ -0,0 +1,157 @@
+/*
+ * Licensed to Yahoo! under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  Yahoo! licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.giraph;
+
+import java.util.List;
+
+import org.apache.giraph.zk.ZooKeeperExt;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs.Ids;
+
+import junit.framework.TestCase;
+
+public class TestZooKeeperExt
+        extends TestCase implements Watcher {
+    /** ZooKeeperExt instance */
+    private ZooKeeperExt zooKeeperExt = null;
+    /** ZooKeeper server list */
+    private String zkList = System.getProperty("prop.zookeeper.list");
+
+    public final String BASE_PATH = "/_zooKeeperExtTest";
+    public final String FIRST_PATH = "/_first";
+
+    public void process(WatchedEvent event) {
+        return;
+    }
+
+    @Override
+    public void setUp() {
+        try {
+            if (zkList == null) {
+                return;
+            }
+            zooKeeperExt =
+                new ZooKeeperExt(zkList, 30*1000, this);
+            zooKeeperExt.deleteExt(BASE_PATH, -1, true);
+        } catch (KeeperException.NoNodeException e) {
+            System.out.println("Clean start: No node " + BASE_PATH);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public void tearDown() {
+        if (zooKeeperExt == null) {
+            return;
+        }
+        try {
+            zooKeeperExt.close();
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    public void testCreateExt() throws KeeperException, InterruptedException {
+        if (zooKeeperExt == null) {
+            System.out.println(
+                "testCreateExt: No prop.zookeeper.list set, skipping test");
+            return;
+        }
+        System.out.println("Created: " +
+            zooKeeperExt.createExt(
+                BASE_PATH + FIRST_PATH,
+                null,
+                Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT,
+                true));
+        zooKeeperExt.delete(BASE_PATH + FIRST_PATH, -1);
+        zooKeeperExt.delete(BASE_PATH, -1);
+    }
+
+    public void testDeleteExt() throws KeeperException, InterruptedException {
+        if (zooKeeperExt == null) {
+            System.out.println(
+                "testDeleteExt: No prop.zookeeper.list set, skipping test");
+            return;
+        }
+        zooKeeperExt.create(BASE_PATH,
+                              null,
+                              Ids.OPEN_ACL_UNSAFE,
+                              CreateMode.PERSISTENT);
+        zooKeeperExt.create(BASE_PATH + FIRST_PATH,
+                                null,
+                                Ids.OPEN_ACL_UNSAFE,
+                                CreateMode.PERSISTENT);
+        try {
+            zooKeeperExt.deleteExt(BASE_PATH, -1, false);
+        } catch (KeeperException.NotEmptyException e) {
+            System.out.println(
+                "Correctly failed to delete since not recursive");
+        }
+        zooKeeperExt.deleteExt(BASE_PATH, -1, true);
+    }
+
+    public void testGetChildrenExt()
+        throws KeeperException, InterruptedException {
+        if (zooKeeperExt == null) {
+           System.out.println(
+               "testGetChildrenExt: No prop.zookeeper.list set, skipping 
test");
+           return;
+        }
+        zooKeeperExt.create(BASE_PATH,
+                              null,
+                              Ids.OPEN_ACL_UNSAFE,
+                              CreateMode.PERSISTENT);
+        zooKeeperExt.create(BASE_PATH + "/b",
+                null,
+                Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT_SEQUENTIAL);
+        zooKeeperExt.create(BASE_PATH + "/a",
+                null,
+                Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT_SEQUENTIAL);
+        zooKeeperExt.create(BASE_PATH + "/d",
+                null,
+                Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT_SEQUENTIAL);
+        zooKeeperExt.create(BASE_PATH + "/c",
+                null,
+                Ids.OPEN_ACL_UNSAFE,
+                CreateMode.PERSISTENT_SEQUENTIAL);
+        List<String> fullPathList =
+            zooKeeperExt.getChildrenExt(BASE_PATH, false, false, true);
+        for (String fullPath : fullPathList) {
+            assertTrue(fullPath.contains(BASE_PATH + "/"));
+        }
+        List<String> sequenceOrderedList =
+            zooKeeperExt.getChildrenExt(BASE_PATH, false, true, true);
+        for (String fullPath : sequenceOrderedList) {
+            assertTrue(fullPath.contains(BASE_PATH + "/"));
+        }
+        assertTrue(sequenceOrderedList.size() == 4);
+        assertTrue(sequenceOrderedList.get(0).contains("/b"));
+        assertTrue(sequenceOrderedList.get(1).contains("/a"));
+        assertTrue(sequenceOrderedList.get(2).contains("/d"));
+        assertTrue(sequenceOrderedList.get(3).contains("/c"));
+    }
+}


Reply via email to