[ 
https://issues.apache.org/jira/browse/APEXMALHAR-2045?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15346565#comment-15346565
 ] 

ASF GitHub Bot commented on APEXMALHAR-2045:
--------------------------------------------

Github user vrozov commented on a diff in the pull request:

    https://github.com/apache/apex-malhar/pull/279#discussion_r68251593
  
    --- Diff: 
library/src/test/java/com/datatorrent/lib/bandwidth/BandwidthManagerTest.java 
---
    @@ -0,0 +1,150 @@
    +/**
    + * 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.bandwidth;
    +
    +import java.io.File;
    +import java.io.IOException;
    +
    +import org.junit.Assert;
    +import org.junit.Rule;
    +import org.junit.Test;
    +import org.junit.rules.TestWatcher;
    +import org.junit.runner.Description;
    +import org.apache.commons.io.FileUtils;
    +
    +import com.datatorrent.api.Attribute;
    +import com.datatorrent.api.Context;
    +import com.datatorrent.api.DAG;
    +import com.datatorrent.lib.helper.OperatorContextTestHelper;
    +
    +public class BandwidthManagerTest
    +{
    +  private static class TestMeta extends TestWatcher
    +  {
    +    private String applicationPath;
    +    private BandwidthManager underTest;
    +    private Context.OperatorContext context;
    +    private long bandwidthLimit = 10L;
    +    private ScheduledExecutorTestService mockschedular;
    +
    +    @Override
    +    protected void starting(Description description)
    +    {
    +      super.starting(description);
    +      mockschedular = new ScheduledExecutorTestService();
    +      underTest = new BandwidthManager(mockschedular);
    +      underTest.setBandwidth(bandwidthLimit);
    +
    +      applicationPath = "target/" + description.getClassName() + "/" + 
description.getMethodName();
    +      Attribute.AttributeMap.DefaultAttributeMap attributes = new 
Attribute.AttributeMap.DefaultAttributeMap();
    +      attributes.put(DAG.APPLICATION_PATH, applicationPath);
    +      context = new OperatorContextTestHelper.TestIdOperatorContext(1, 
attributes);
    +      underTest.setup(context);
    +    }
    +
    +    @Override
    +    protected void finished(Description description)
    +    {
    +      underTest.teardown();
    +      try {
    +        FileUtils.deleteDirectory(new File("target/" + 
description.getClassName()));
    +      } catch (IOException e) {
    +        throw new RuntimeException(e);
    +      }
    +    }
    +  }
    +
    +  @Rule
    +  public TestMeta testMeta = new TestMeta();
    +
    +  @Test
    +  public void testBandwidthForLargeBlocks() throws InterruptedException
    +  {
    +    String data = "Tuple: test data to be emitted.";
    +    long startTime = System.currentTimeMillis();
    +    testMeta.underTest.consumeBandwidth(data.length());
    +    while (!testMeta.underTest.canConsumeBandwidth()) {
    +      Thread.sleep(1000);
    --- End diff --
    
    There is no second thread and waiting for a second here only adds 
unnecessary wait time to overall test time. Using count instead of relying on 
System.currentTimeMillis() will not change test logic assuming that 
Thread.sleep(1000) correctly sleeps for 1 sec.


> Add bandwidth control feature to Apex
> -------------------------------------
>
>                 Key: APEXMALHAR-2045
>                 URL: https://issues.apache.org/jira/browse/APEXMALHAR-2045
>             Project: Apache Apex Malhar
>          Issue Type: Task
>            Reporter: Priyanka Gugale
>            Assignee: Priyanka Gugale
>
>  bandwidth restrictions on input operator for number of bytes to be consumed 
> per second.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to