Example usage for org.apache.hadoop.fs FileSystem getLocal

List of usage examples for org.apache.hadoop.fs FileSystem getLocal

Introduction

In this page you can find the example usage for org.apache.hadoop.fs FileSystem getLocal.

Prototype

public static LocalFileSystem getLocal(Configuration conf) throws IOException 

Source Link

Document

Get the local FileSystem.

Usage

From source file:gaffer.accumulo.inputformat.TestElementInputFormat.java

License:Apache License

public void testPostRollUpTransformIsAppliedReadingDataForPairs(InputFormatType type) throws Exception {
    String INSTANCE_NAME = "A";
    String tableName = "testPostRollUpTransformIsAppliedReadingDataForPairs" + type.name();
    MockInstance mockInstance = new MockInstance(INSTANCE_NAME);
    Connector connector = mockInstance.getConnector("root", new PasswordToken(""));
    connector.securityOperations().changeUserAuthorizations("root",
            new Authorizations(visibilityString1, visibilityString2));// TEMP _ CHECK
    TableUtils.createTable(connector, tableName, 30 * 24 * 60 * 60 * 1000L);
    Set<GraphElementWithStatistics> data = getData();
    AccumuloBackedGraph graph = new AccumuloBackedGraph(connector, tableName);
    graph.addGraphElementsWithStatistics(data);

    // Add post roll-up transform
    String transformedSummaryType = "abc";

    // Set up local conf
    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    FileSystem fs = FileSystem.getLocal(conf);
    DriverForPairs driver = new DriverForPairs(type, new ExampleTransform(transformedSummaryType));
    driver.setConf(conf);//from www. j a v  a  2 s  .  c  o m

    // Create output folder for MapReduce job
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    // Write properties file
    String accumuloPropertiesFilename = tempFolder.newFile().getAbsolutePath();
    BufferedWriter bw = new BufferedWriter(new FileWriter(accumuloPropertiesFilename));
    bw.write("accumulo.instance=" + INSTANCE_NAME + "\n");
    bw.write("accumulo.zookeepers=" + AccumuloConfig.MOCK_ZOOKEEPERS + "\n");
    bw.write("accumulo.table=" + tableName + "\n");
    bw.write("accumulo.user=root\n");
    bw.write("accumulo.password=\n");
    bw.close();

    // Run job
    assertEquals(0, driver
            .run(new String[] { accumuloPropertiesFilename, outputDir, "customer", "B", "product", "Q" }));

    // Read results in
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(outputDir + "/part-m-00000"), conf);
    GraphElement element = new GraphElement();
    SetOfStatistics statistics = new SetOfStatistics();
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    while (reader.next(element, statistics)) {
        results.add(new GraphElementWithStatistics(element.clone(), statistics.clone()));
        assertEquals(transformedSummaryType, element.getSummaryType());
    }
    reader.close();

    // There should be 1 edge
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge5 = new Edge("customer", "B", "product", "Q", transformedSummaryType, "instore", true,
            visibilityString2, sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics5 = new SetOfStatistics();
    statistics5.addStatistic("count", new Count(99));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge5), statistics5));

    assertEquals(results, expectedResults);
}

From source file:gaffer.accumulo.inputformat.TestExampleDriver.java

License:Apache License

@Test
public void testFullTableScan() throws Exception {
    String instanceName = "testFullTableScan";
    String tableName = "table" + instanceName;
    MockInstance mockInstance = new MockInstance(instanceName);
    Connector connector = mockInstance.getConnector("root", new PasswordToken(""));
    TableUtils.createTable(connector, tableName, 30 * 24 * 60 * 60 * 1000L);
    Set<GraphElementWithStatistics> data = getData();
    AccumuloBackedGraph graph = new AccumuloBackedGraph(connector, tableName);
    graph.addGraphElementsWithStatistics(data);

    String accumuloPropertiesFilename = tempFolder.newFile().getAbsolutePath();
    BufferedWriter bw = new BufferedWriter(new FileWriter(accumuloPropertiesFilename));
    bw.write("accumulo.instance=" + instanceName + "\n");
    bw.write("accumulo.zookeepers=" + AccumuloConfig.MOCK_ZOOKEEPERS + "\n");
    bw.write("accumulo.table=" + tableName + "\n");
    bw.write("accumulo.user=root\n");
    bw.write("accumulo.password=\n");
    bw.close();//from   www . j  a v a  2  s  .  c  o m

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    FileSystem fs = FileSystem.getLocal(conf);

    ExampleDriver driver = new ExampleDriver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    driver.run(new String[] { outputDir, accumuloPropertiesFilename, "0", "null", "null", "true" });

    // Read results in
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(outputDir + "/part-m-00000"), conf);
    GraphElement element = new GraphElement();
    SetOfStatistics statistics = new SetOfStatistics();
    int count = 0;
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    while (reader.next(element, statistics)) {
        count++;
        results.add(new GraphElementWithStatistics(element.clone(), statistics.clone()));
    }
    reader.close();
    // There should be 3 edges and 2 entities - 5 in total
    // Note need to check count (and not just compare sets) as the point of the test is to
    // ensure we don't get the same edge back twice
    assertEquals(5, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge1 = new Edge("customer", "A", "product", "P", "purchase", "instore", true, visibilityString1,
            sevenDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics1 = new SetOfStatistics();
    statistics1.addStatistic("count", new Count(20));
    statistics1.addStatistic("anotherCount", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge1), statistics1));
    Edge edge2 = new Edge("customer", "A", "product", "P", "purchase", "instore", false, visibilityString1,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics2 = new SetOfStatistics();
    statistics2.addStatistic("countSomething", new Count(123456));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge2), statistics2));
    Edge edge5 = new Edge("customer", "B", "product", "Q", "purchase", "instore", true, visibilityString2,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics5 = new SetOfStatistics();
    statistics5.addStatistic("count", new Count(99));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge5), statistics5));
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));
    Entity entity2 = new Entity("product", "R", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity2 = new SetOfStatistics();
    statisticsEntity2.addStatistic("entity_count", new Count(12345));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity2), statisticsEntity2));

    assertEquals(results, expectedResults);
}

From source file:gaffer.accumulo.inputformat.TestExampleDriver.java

License:Apache License

@Test
public void testReadOneSeed() throws Exception {
    String instanceName = "testReadOneSeed";
    String tableName = "table" + instanceName;
    MockInstance mockInstance = new MockInstance(instanceName);
    Connector connector = mockInstance.getConnector("root", new PasswordToken(""));
    TableUtils.createTable(connector, tableName, 30 * 24 * 60 * 60 * 1000L);
    Set<GraphElementWithStatistics> data = getData();
    AccumuloBackedGraph graph = new AccumuloBackedGraph(connector, tableName);
    graph.addGraphElementsWithStatistics(data);

    String accumuloPropertiesFilename = tempFolder.newFile().getAbsolutePath();
    BufferedWriter bw = new BufferedWriter(new FileWriter(accumuloPropertiesFilename));
    bw.write("accumulo.instance=" + instanceName + "\n");
    bw.write("accumulo.zookeepers=" + AccumuloConfig.MOCK_ZOOKEEPERS + "\n");
    bw.write("accumulo.table=" + tableName + "\n");
    bw.write("accumulo.user=root\n");
    bw.write("accumulo.password=\n");
    bw.close();//from w  ww  .  j a v a 2  s .c  om

    String seedFilename = tempFolder.newFile().getAbsolutePath();
    bw = new BufferedWriter(new FileWriter(seedFilename));
    bw.write("product|R\n");
    bw.close();

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    FileSystem fs = FileSystem.getLocal(conf);

    ExampleDriver driver = new ExampleDriver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);
    driver.run(
            new String[] { outputDir, accumuloPropertiesFilename, "0", "null", "null", "true", seedFilename });

    // Read results in
    SequenceFile.Reader reader = new SequenceFile.Reader(fs, new Path(outputDir + "/part-m-00000"), conf);
    GraphElement element = new GraphElement();
    SetOfStatistics statistics = new SetOfStatistics();
    int count = 0;
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    while (reader.next(element, statistics)) {
        count++;
        results.add(new GraphElementWithStatistics(element.clone(), statistics.clone()));
    }
    reader.close();
    // There should be 1 entity
    assertEquals(1, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Entity entity2 = new Entity("product", "R", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity2 = new SetOfStatistics();
    statisticsEntity2.addStatistic("entity_count", new Count(12345));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity2), statisticsEntity2));

    assertEquals(results, expectedResults);
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValuesNoView() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValuesNoView";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    graph.setConfiguration(conf, new TypeValue("customer", "A"), accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run with no view
    Driver driver = new Driver();
    driver.setConf(conf);//w ww. java  2  s. c o  m
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir); // Need to delete this as Junit will create the folder

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 2 edges and 1 entity
    assertEquals(3, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge1 = new Edge("customer", "A", "product", "P", "purchase", "instore", true, visibilityString1,
            sevenDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics1 = new SetOfStatistics();
    statistics1.addStatistic("count", new Count(20));
    statistics1.addStatistic("anotherCount", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge1), statistics1));
    Edge edge2 = new Edge("customer", "A", "product", "P", "purchase", "instore", false, visibilityString1,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics2 = new SetOfStatistics();
    statistics2.addStatistic("countSomething", new Count(123456));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge2), statistics2));
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));

    assertEquals(expectedResults, results);

    // Repeat but also ask for customer B
    driver = new Driver();
    conf = new JobConf();
    Set<TypeValue> typeValues = new HashSet<TypeValue>();
    typeValues.add(new TypeValue("customer", "A"));
    typeValues.add(new TypeValue("customer", "B"));
    graph.setConfiguration(conf, typeValues, accumuloConfig);
    driver.setConf(conf);
    outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    results = new HashSet<GraphElementWithStatistics>();
    count = readResults(fs, new Path(outputDir), results);

    // There should be 3 edges and 1 entity
    assertEquals(4, count);
    Edge edge5 = new Edge("customer", "B", "product", "Q", "purchase", "instore", true, visibilityString2,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics5 = new SetOfStatistics();
    statistics5.addStatistic("count", new Count(99));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge5), statistics5));

    assertEquals(expectedResults, results);
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValuesSummaryView() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValuesSummaryView";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    graph.setSummaryTypesAndSubTypes(new Pair<String>("purchase", "count"));
    graph.setConfiguration(conf, new TypeValue("customer", "A"), accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run/*  w w w  . j  a v  a  2  s.c  o  m*/
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 2 entities
    assertEquals(1, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));

    assertEquals(expectedResults, results);
    graph.setReturnAllSummaryTypesAndSubTypes();
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValuesTimeWindowView() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValuesTimeWindowView";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    graph.setTimeWindow(sevenDaysBefore, sixDaysBefore);
    graph.setConfiguration(conf, new TypeValue("customer", "A"), accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run// w  w w . j av a  2s .c o  m
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 1 entity and 1 edge
    assertEquals(2, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge1 = new Edge("customer", "A", "product", "P", "purchase", "instore", true, visibilityString1,
            sevenDaysBefore, sixDaysBefore);
    SetOfStatistics statistics1 = new SetOfStatistics();
    statistics1.addStatistic("count", new Count(1));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge1), statistics1));
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));

    assertEquals(expectedResults, results);
    graph.setTimeWindowToAllTime();
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValuesAndEntitiesOnly() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValuesAndEntitiesOnly";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    graph.setTimeWindow(sevenDaysBefore, sixDaysBefore);
    graph.setReturnEntitiesOnly();/*w w  w  .  ja v a 2  s.c  o  m*/
    graph.setConfiguration(conf, new TypeValue("customer", "A"), accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 1 entity
    assertEquals(1, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));

    assertEquals(expectedResults, results);
    graph.setTimeWindowToAllTime();
    graph.setReturnEntitiesAndEdges();
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValuesAndEdgesOnly() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValuesAndEdgesOnly";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    graph.setTimeWindow(sevenDaysBefore, sixDaysBefore);
    graph.setReturnEdgesOnly();//from   w  w  w  .j av a  2s .c o m
    graph.setConfiguration(conf, new TypeValue("customer", "A"), accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 1 edge
    assertEquals(1, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge1 = new Edge("customer", "A", "product", "P", "purchase", "instore", true, visibilityString1,
            sevenDaysBefore, sixDaysBefore);
    SetOfStatistics statistics1 = new SetOfStatistics();
    statistics1.addStatistic("count", new Count(1));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge1), statistics1));

    assertEquals(expectedResults, results);
    graph.setTimeWindowToAllTime();
    graph.setReturnEntitiesAndEdges();
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithTypeValueRanges() throws Exception {
    String instanceName = "testSetConfigurationWithTypeValueRanges";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    TypeValueRange range = new TypeValueRange("customer", "A", "customer", "Z");
    graph.setConfigurationFromRanges(conf, range, accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run/*from ww  w .ja  v a 2 s. c  o  m*/
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 3 edges and 1 entity
    assertEquals(4, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge1 = new Edge("customer", "A", "product", "P", "purchase", "instore", true, visibilityString1,
            sevenDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics1 = new SetOfStatistics();
    statistics1.addStatistic("count", new Count(20));
    statistics1.addStatistic("anotherCount", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge1), statistics1));
    Edge edge4 = new Edge("customer", "A", "product", "P", "purchase", "instore", false, visibilityString2,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics4 = new SetOfStatistics();
    statistics4.addStatistic("countSomething", new Count(123456));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge4), statistics4));
    Edge edge5 = new Edge("customer", "B", "product", "Q", "purchase", "instore", true, visibilityString2,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics5 = new SetOfStatistics();
    statistics5.addStatistic("count", new Count(99));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge5), statistics5));
    Entity entity1 = new Entity("customer", "A", "purchase", "count", visibilityString1, sevenDaysBefore,
            sixDaysBefore);
    SetOfStatistics statisticsEntity1 = new SetOfStatistics();
    statisticsEntity1.addStatistic("entity_count", new Count(1000000));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(entity1), statisticsEntity1));

    assertEquals(expectedResults, results);
}

From source file:gaffer.accumulo.TestAccumuloBackedGraphUpdatingConf.java

License:Apache License

@Test
public void testSetConfigurationWithPairs() throws Exception {
    String instanceName = "testSetConfigurationWithPairs";
    AccumuloBackedGraph graph = setUpGraphAndMockAccumulo(instanceName);
    AccumuloConfig accumuloConfig = setUpAccumuloConfig(instanceName);

    JobConf conf = new JobConf();
    conf.set("fs.default.name", "file:///");
    conf.set("mapred.job.tracker", "local");
    Pair<TypeValue> pair = new Pair<TypeValue>(new TypeValue("customer", "B"), new TypeValue("product", "Q"));
    graph.setConfigurationFromPairs(conf, pair, accumuloConfig);
    FileSystem fs = FileSystem.getLocal(conf);

    // Run//w  ww  .j  a va2s.c  o  m
    Driver driver = new Driver();
    driver.setConf(conf);
    String outputDir = tempFolder.newFolder().getAbsolutePath();
    FileUtils.deleteDirectory(outputDir);

    assertEquals(0, driver.run(new String[] { outputDir }));

    // Read results in
    Set<GraphElementWithStatistics> results = new HashSet<GraphElementWithStatistics>();
    int count = readResults(fs, new Path(outputDir), results);

    // There should be 1 edge
    assertEquals(1, count);
    Set<GraphElementWithStatistics> expectedResults = new HashSet<GraphElementWithStatistics>();
    Edge edge5 = new Edge("customer", "B", "product", "Q", "purchase", "instore", true, visibilityString2,
            sixDaysBefore, fiveDaysBefore);
    SetOfStatistics statistics5 = new SetOfStatistics();
    statistics5.addStatistic("count", new Count(99));
    expectedResults.add(new GraphElementWithStatistics(new GraphElement(edge5), statistics5));

    assertEquals(expectedResults, results);
}