Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed 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.facebook.presto.operator;
 
 
 import java.util.List;
 
 import static com.facebook.presto.SessionTestUtils.TEST_SESSION;
 import static com.facebook.presto.spi.type.BigintType.BIGINT;
 import static com.facebook.presto.spi.type.VarcharType.VARCHAR;
 import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
 import static io.airlift.concurrent.Threads.daemonThreadsNamed;
 import static java.util.concurrent.Executors.newCachedThreadPool;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 
 @Test(singleThreaded = true)
 {
     private ExecutorService executor;
     private DriverContext driverContext;
 
     @BeforeMethod
     public void setUp()
     {
          = newCachedThreadPool(daemonThreadsNamed("test-%s"));
          = new TaskContext(new TaskId("query""stage""task"), )
                 .addPipelineContext(truetrue)
                 .addDriverContext();
     }
 
     @AfterMethod
     public void tearDown()
     {
         .shutdownNow();
     }
 
     @Test
     public void testSingleColumn()
             throws Exception
     {
         InMemoryRecordSet records = new InMemoryRecordSet(ImmutableList.of(), ImmutableList.copyOf(new List<?>[] {ImmutableList.of("abc"), ImmutableList.of("def"),
                                                                                                                         ImmutableList.of("g")}));
 
         OperatorContext operatorContext = .addOperatorContext(0, RecordProjectOperator.class.getSimpleName());
         Operator operator = new RecordProjectOperator(operatorContextrecords);
 
                 .row("abc")
                 .row("def")
                 .row("g")
                 .build();
 
         OperatorAssertion.assertOperatorEquals(operatorexpected);
     }
 
     @Test
     public void testMultiColumn()
             throws Exception
     {
         InMemoryRecordSet records = new InMemoryRecordSet(ImmutableList.of(), ImmutableList.of(
                 ImmutableList.of("abc", 1L),
                 ImmutableList.of("def", 2L),
                 ImmutableList.of("g", 0L)));
 
         OperatorContext operatorContext = .addOperatorContext(0, RecordProjectOperator.class.getSimpleName());
         Operator operator = new RecordProjectOperator(operatorContextrecords);
 
                 .row("abc", 1)
                 .row("def", 2)
                 .row("g", 0)
                 .build();
 
         OperatorAssertion.assertOperatorEquals(operatorexpected);
     }
    @Test
    public void testFinish()
            throws Exception
    {
        InfiniteRecordSet records = new InfiniteRecordSet(ImmutableList.<Type>of(), ImmutableList.of("abc", 1L));
        Operator operator = new RecordProjectOperator(operatorContextrecords);
        // verify initial state
        assertEquals(operator.isFinished(), false);
        assertEquals(operator.needsInput(), false);
        // first read will be null due to buffering
        assertNull(operator.getOutput());
        // read first page
        Page page = null;
        for (int i = 0; i < 100; i++) {
            page = operator.getOutput();
            if (page != null) {
                break;
            }
        }
        assertNotNull(page);
        // verify state
        assertEquals(operator.isFinished(), false);
        assertEquals(operator.needsInput(), false);
        // start second page... will be null due to buffering
        assertNull(operator.getOutput());
        // verify state
        assertEquals(operator.isFinished(), false);
        assertEquals(operator.needsInput(), false);
        // finish
        operator.finish();
        // verify state
        assertEquals(operator.isFinished(), false);
        assertEquals(operator.needsInput(), false);
        // read the buffered page
        assertNotNull(operator.getOutput());
        // verify state
        assertEquals(operator.isFinished(), true);
        assertEquals(operator.needsInput(), false);
        assertEquals(operator.getOutput(), null);
    }
New to GrepCode? Check out our FAQ X