Code Monkey home page Code Monkey logo

ncats-common's Introduction

NCATS-Common

Common Utility classes used in multiple NIH/NCATS informatics projects.

How to include in Java Project

NCATS-common is available on Maven Central

<dependency>
    <groupId>gov.nih.ncats</groupId>
    <artifactId>ncats-common</artifactId>
    <version>0.3.6</version>
</dependency>

License

This project is Open Sourced under the Apache 2.0

This product includes software based on Yield-Java created by Benji Weber under MIT license. A copy of that license is located in derivedWorkLicenses/Yield-Java-LICENSE.txt

ncats-common's People

Contributors

dependabot[bot] avatar dkatzel-home avatar dkatzel-ncats avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dkatzel-ncats

ncats-common's Issues

Exception not bubbled to the consumer, need write access to push repro PR

package gov.nih.ncats.common;

import gov.nih.ncats.common.yield.Yield;
import org.junit.Test;

import java.rmi.UnexpectedException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

public class MoreYieldTest {

@Test public void getOneToFive() throws Exception {
    Iterator<Integer> i = new CustomGenerator(1, 10).call(4, null, null);
    List<Integer> l = new ArrayList<>();
    while (i.hasNext()) {
        l.add(i.next());
    }

    assertIterableEquals(l, Arrays.asList(0, 1, 2, 3));
}

@Test public void getOneToN() throws Exception {
    // this seems too slow takes 3secs, can it have a buffer of N(1000) so generator can pre-generate records
    Integer max = 1_000_000;
    Iterator<Integer> i = new CustomGenerator(1000, Integer.MAX_VALUE).call(max, null, null);
    List<Integer> l = new ArrayList<>();
    while (i.hasNext()) {
        l.add(i.next());
    }

    assertEquals(l.size(), max);
}

@Test public void exceptionTest() throws Exception {
    // hangs on error, exception not surfaced to caller
    Iterator<Integer> i = new CustomGenerator(1, 3).call(10, null, null);
    i.next();
    i.next();
    String expectedMessage = "foo";

    Exception e = assertThrows(RuntimeException.class, () -> { i.next();i.next(); });
    assertTrue(e.getCause().getMessage().contains(expectedMessage));

    Iterator<Integer> i2 = new CustomGenerator(10, 2).call(3, null, null);
    try {
        while (i2.hasNext()) {
            i2.next();
        }
        throw new UnexpectedException("should not reach here");
    } catch (RuntimeException e1) {
        assertTrue(e.getCause().getMessage().contains(expectedMessage));
    }
}

}

class CustomGenerator {
private final int throwAt;
public CustomGenerator(int bufferSize, int throwAt) {
this.throwAt = throwAt;
}

public Iterator<Integer> call(Integer key, Iterator<String> left, Iterator<String> right) throws Exception {
    return call(key).iterator();
}

public Yield<Integer> call(Integer key) {
    return Yield.create(yielder -> {
        for(int i = 0;i <key; i++) {
            if(i==throwAt) throw new NullPointerException("foo");
            yielder.returning(i);
        }
    });
}

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.