package edu.washington.escience.myria.binary;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Arrays;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.washington.escience.myria.Schema;
import edu.washington.escience.myria.Type;
import edu.washington.escience.myria.operator.BinaryFileScan;
import edu.washington.escience.myria.operator.SinkRoot;
import edu.washington.escience.myria.tipsy.TipsyFileScanSpeedTest;

public class BinaryFileScanSpeedTest {
  /** The logger for this class. */
  private static final Logger LOGGER = LoggerFactory.getLogger(TipsyFileScanSpeedTest.class);

  @Test
  public void binaryFileScanTest() throws Exception {
    /* The three files */
    File binaryFile = new File("data_nocommit/speedtest/dbcosmo50/cosmo50cmb.256g2bwK.00128.star.bin");
    /* We can read them, right? */
    assertTrue(binaryFile.canRead());

    Type[] typeAr = { Type.LONG_TYPE, // iOrder
        Type.FLOAT_TYPE, // mass
        Type.FLOAT_TYPE, // x
        Type.FLOAT_TYPE, // y
        Type.FLOAT_TYPE, // z
        Type.FLOAT_TYPE, // vx
        Type.FLOAT_TYPE, // vy
        Type.FLOAT_TYPE, // vz
        Type.FLOAT_TYPE, // rho
        Type.FLOAT_TYPE, // temp
        Type.FLOAT_TYPE, // hsmooth
        Type.FLOAT_TYPE, // metals
        Type.FLOAT_TYPE, // tform
        Type.FLOAT_TYPE, // eps
        Type.FLOAT_TYPE // phi
        };
    Schema schema = new Schema(Arrays.asList(typeAr));

    BinaryFileScan scan = new BinaryFileScan(schema, binaryFile.getAbsolutePath());
    SinkRoot sink = new SinkRoot(scan, 1000 * 1000);
    sink.open(null);
    while (!sink.eos()) {
      sink.nextReady();
    }
    sink.close();
    LOGGER.info("Read {} tuples from the file.", sink.getCount());
  }
}

@@ -36,24 +36,69 @@
 ia.binary;%0A%0A
+import static org.junit.Assert.assertEquals;%0A
 import stati
@@ -1235,109 +1235,8 @@
  vz%0A
-        Type.FLOAT_TYPE, // rho%0A        Type.FLOAT_TYPE, // temp%0A        Type.FLOAT_TYPE, // hsmooth%0A
     
@@ -1266,16 +1266,16 @@
  metals%0A
+
         
@@ -1359,16 +1359,17 @@
 TYPE
+,
  // phi%0A
     
@@ -1364,20 +1364,16 @@
  // phi%0A
-    
     %7D;%0A 
@@ -1552,21 +1552,8 @@
 scan
-, 1000 * 1000
 );%0A 
@@ -1642,24 +1642,24 @@
 nk.close();%0A
-
     LOGGER.i
@@ -1713,14 +1713,58 @@
 unt());%0A
+    assertEquals(2743966, sink.getCount());%0A
   %7D%0A%7D%0A

use correct schema for star files; check answer