Search in sources :

Example 1 with PartialResultExecutor

use of org.teiid.translator.google.api.result.PartialResultExecutor in project teiid by teiid.

the class RowsResultTest method twoBatchCallsNeeded.

@Test
public void twoBatchCallsNeeded() {
    final List<SheetRow> firstPart = new ArrayList<SheetRow>();
    final List<SheetRow> secondPart = new ArrayList<SheetRow>();
    final List<SheetRow> all = new ArrayList<SheetRow>();
    firstPart.add(new SheetRow(new String[] { "a", "b", "c" }));
    firstPart.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    firstPart.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    secondPart.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    secondPart.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.addAll(firstPart);
    all.addAll(secondPart);
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called++ > 2)
                Assert.fail("getResultsBatch at most twice");
            if (called == 1) {
                return firstPart;
            } else if (called == 2) {
                return secondPart;
            }
            // Shouldn't reach here.
            return null;
        }
    }, 3);
    int i = 0;
    for (SheetRow row : result) {
        Assert.assertEquals(row, all.get(i++));
    }
    Assert.assertEquals("Six rows should be in the result", 5, i);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Example 2 with PartialResultExecutor

use of org.teiid.translator.google.api.result.PartialResultExecutor in project teiid by teiid.

the class RowsResultTest method noRows.

@Test
public void noRows() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called++ > 1)
                Assert.fail("getResultsBatch at once");
            return all;
        }
    }, 3);
    int i = 0;
    for (SheetRow row : result) {
        i++;
    }
    Assert.assertEquals("No iterations should be made", 0, i);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Example 3 with PartialResultExecutor

use of org.teiid.translator.google.api.result.PartialResultExecutor in project teiid by teiid.

the class RowsResultTest method sixBatchCalls.

@Test
public void sixBatchCalls() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    all.add(new SheetRow(new String[] { "a", "b", "c" }));
    all.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    all.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    all.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    all.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.add(new SheetRow(new String[] { "a6", "b6", "c6" }));
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called > 6)
                Assert.fail("getResultsBatch at least 6 times");
            if (called == 6)
                return new ArrayList<SheetRow>();
            return Collections.singletonList(all.get(called++));
        }
    }, 1);
    int i = 0;
    for (SheetRow row : result) {
        Assert.assertEquals(all.get(i++), row);
    }
    Assert.assertEquals("Six iterations should be made", 6, i);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Example 4 with PartialResultExecutor

use of org.teiid.translator.google.api.result.PartialResultExecutor in project teiid by teiid.

the class RowsResultTest method offsetTestOne.

@Test
public void offsetTestOne() {
    final List<SheetRow> all = new ArrayList<SheetRow>();
    all.add(new SheetRow(new String[] { "a", "b", "c" }));
    all.add(new SheetRow(new String[] { "a2", "b2", "c2" }));
    all.add(new SheetRow(new String[] { "a3", "b3", "c3" }));
    all.add(new SheetRow(new String[] { "a4", "b4", "c4" }));
    all.add(new SheetRow(new String[] { "a5", "b5", "c5" }));
    all.add(new SheetRow(new String[] { "a6", "b6", "c6" }));
    RowsResult result = new RowsResult(new PartialResultExecutor() {

        int called = 0;

        @Override
        public List<SheetRow> getResultsBatch(int startIndex, int endIndex) {
            if (called++ > 2)
                Assert.fail("getResultsBatch at most 3 times");
            ArrayList<SheetRow> result = new ArrayList<SheetRow>();
            if (called == 1) {
                result.add(all.get(1));
                result.add(all.get(2));
            } else if (called == 2) {
                result.add(all.get(3));
                result.add(all.get(4));
            } else if (called == 3)
                result.add(all.get(5));
            return result;
        }
    }, 2);
    result.setOffset(1);
    result.setLimit(6);
    int i = 1;
    for (SheetRow row : result) {
        Assert.assertEquals(all.get(i++), row);
    }
    Assert.assertEquals("5 iterations should be made", 5, i - 1);
}
Also used : SheetRow(org.teiid.translator.google.api.result.SheetRow) ArrayList(java.util.ArrayList) PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) List(java.util.List) ArrayList(java.util.ArrayList) RowsResult(org.teiid.translator.google.api.result.RowsResult) Test(org.junit.Test)

Example 5 with PartialResultExecutor

use of org.teiid.translator.google.api.result.PartialResultExecutor in project teiid by teiid.

the class SpreadsheetDataRetrievalTest method vSimple.

@Test
public void vSimple() {
    PartialResultExecutor dpqs = dataProtocol.new DataProtocolQueryStrategy(SPREADSHEET_KEY, "s1", "");
    assertSimpleResultDataProtorol(dpqs);
}
Also used : PartialResultExecutor(org.teiid.translator.google.api.result.PartialResultExecutor) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 PartialResultExecutor (org.teiid.translator.google.api.result.PartialResultExecutor)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 RowsResult (org.teiid.translator.google.api.result.RowsResult)6 SheetRow (org.teiid.translator.google.api.result.SheetRow)6