apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yogidevendra <...@git.apache.org>
Subject [GitHub] incubator-apex-malhar pull request: APEXMALHAR-2015: Projection Op...
Date Fri, 18 Mar 2016 12:49:40 GMT
Github user yogidevendra commented on a diff in the pull request:

    https://github.com/apache/incubator-apex-malhar/pull/217#discussion_r56650591
  
    --- Diff: library/src/test/java/com/datatorrent/lib/projection/ProjectionTest.java ---
    @@ -0,0 +1,264 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF 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 com.datatorrent.lib.projection;
    +
    +import java.lang.reflect.Field;
    +
    +import org.junit.AfterClass;
    +import org.junit.Assert;
    +import org.junit.BeforeClass;
    +import org.junit.Test;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +/**
    + * Tests for ProjectionOperator
    + */
    +
    +public class ProjectionTest
    +{
    +  private static final Logger logger = LoggerFactory.getLogger(ProjectionTest.class);
    +
    +  public static class DummyPOJO
    +  {
    +    private long projected;
    +    private long remainder;
    +
    +    public long getProjected()
    +    {
    +      return projected;
    +    }
    +
    +    public void setProjected(long _projected)
    +    {
    +      projected = _projected;
    +    }
    +
    +    public long getRemainder()
    +    {
    +      return remainder;
    +    }
    +
    +    public void setRemainder(long _remainder)
    +    {
    +      remainder = _remainder;
    +    }
    +  }
    +
    +  public static class ProjectedPOJO
    +  {
    +    private long projected;
    +
    +    public long getProjected()
    +    {
    +      return projected;
    +    }
    +
    +    public void setProjected(long _projected)
    +    {
    +      projected = _projected;
    +    }
    +  }
    +
    +  public static class RemainderPOJO
    +  {
    +    private long remainder;
    +
    +    public long getRemainder()
    +    {
    +      return remainder;
    +    }
    +
    +    public void setRemainder(long _remainder)
    +    {
    +      remainder = _remainder;
    +    }
    +  }
    +
    +  private static DummyProjection projection;
    +  private static DummyPOJO data;
    +
    +  @Test
    +  public void testProjectionRemainder()
    +  {
    +    logger.debug("start round 0");
    +    projection.beginWindow(0);
    +
    +    data.setProjected(1234);
    +    data.setRemainder(6789);
    +
    +    Object p = null;
    +    try {
    +      p = projection.getProjectedObject(data);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +    logger.debug("projected class {}", p.getClass());
    +
    +    for (Field f: p.getClass().getDeclaredFields()) {
    +      f.setAccessible(true);
    +      try {
    +        logger.debug("projected field: {} type: {} val: {}", f.getName(), f.getType(),
f.get(p));
    +      } catch (IllegalAccessException e) {
    +        logger.info("could not access value of field: {} type: {}", f.getName(), f.getType());
    +      }
    +    }
    +
    +    Object r = null;
    +    try {
    +      r = projection.getRemainderObject(data);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +    logger.debug("remainder class {}", r.getClass());
    +
    +    for (Field f: r.getClass().getDeclaredFields()) {
    +      f.setAccessible(true);
    +      try {
    +        logger.debug("projected field: {} type: {} val: {}", f.getName(), f.getType(),
f.get(r));
    +      } catch (IllegalAccessException e) {
    +        logger.info("could not access value of field: {} type: {}", f.getName(), f.getType());
    +      }
    +    }
    +
    +    try {
    +      Assert.assertEquals("projected field value", 1234, p.getClass().getDeclaredField("projected").get(p));
    +      Assert.assertEquals("remainder field value", 6789, r.getClass().getDeclaredField("remainder").get(r));
    +    } catch (NoSuchFieldException e) {
    +      Assert.assertTrue(e instanceof NoSuchFieldException);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +
    +    projection.endWindow();
    +    logger.debug("end round 0");
    +  }
    +
    +  @Test
    +  public void testProjected()
    +  {
    +    logger.debug("start round 0");
    +    projection.beginWindow(0);
    +
    +    data.setProjected(2345);
    +    data.setRemainder(5678);
    +
    +    Object p = null;
    +    try {
    +      p = projection.getProjectedObject(data);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +    logger.debug("projected class {}", p.getClass());
    +
    +    for (Field f: p.getClass().getDeclaredFields()) {
    +      f.setAccessible(true);
    +      try {
    +        logger.debug("projected field: {} type: {} val: {}", f.getName(), f.getType(),
f.get(p));
    +      } catch (IllegalAccessException e) {
    +        logger.info("could not access value of field: {} type: {}", f.getName(), f.getType());
    +      }
    +    }
    +
    +    try {
    +      Assert.assertEquals("projected field value", 2345, p.getClass().getDeclaredField("projected").get(p));
    +    } catch (NoSuchFieldException e) {
    +      Assert.assertTrue(e instanceof NoSuchFieldException);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +
    +    projection.endWindow();
    +    logger.debug("end round 0");
    +  }
    +
    +  @Test
    +  public void testRemainder()
    +  {
    +    logger.debug("start round 0");
    +    projection.beginWindow(0);
    +
    +    data.setProjected(9876);
    +    data.setRemainder(4321);
    +
    +    Object r = null;
    +    try {
    +      r = projection.getRemainderObject(data);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +    logger.debug("remainder class {}", r.getClass());
    +
    +    for (Field f: r.getClass().getDeclaredFields()) {
    +      f.setAccessible(true);
    +      try {
    +        logger.debug("projected field: {} type: {} val: {}", f.getName(), f.getType(),
f.get(r));
    +      } catch (IllegalAccessException e) {
    +        logger.info("could not access value of field: {} type: {}", f.getName(), f.getType());
    +      }
    +    }
    +
    +    try {
    +      Assert.assertEquals("remainder field value", 4321, r.getClass().getDeclaredField("remainder").get(r));
    +    } catch (NoSuchFieldException e) {
    +      Assert.assertTrue(e instanceof NoSuchFieldException);
    +    } catch (IllegalAccessException e) {
    +      Assert.assertTrue(e instanceof IllegalAccessException);
    +    }
    +
    +    projection.endWindow();
    +    logger.debug("end round 0");
    +  }
    +
    +  @Test
    +  public void testProjection()
    +  {
    +    logger.debug("start round 0");
    +    projection.beginWindow(0);
    +
    +    projection.in.process(data);
    +    Assert.assertEquals("projected tuples", 1, projection.projectedTuples);
    --- End diff --
    
    Can we add some more scenarios for this test.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message