Search in sources :

Example 1 with Column

use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle.

the class RowOperationTest method testInvalidAt.

@Test
public void testInvalidAt() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger rowCount = new AtomicInteger();
        se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
            int rowIndex = rowCount.getAndIncrement();
            assertEquals(rowIndex, rc.rowNumber());
            assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
            try {
                rc.at(TEST_COLUMNS.length + 1);
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at(0);
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at(-(TEST_COLUMNS.length + 1));
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at("z");
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            int coIndex = 0;
            for (Column co : rc) {
                coIndex++;
                assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
                for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
                    if (sliceSize == 0)
                        continue;
                    Column coSlice = co.slice(sliceSize);
                    try {
                        coSlice.at(Math.abs(sliceSize) + 1);
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + (sliceSize + 1) + ")");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    try {
                        coSlice.at(0);
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(0)");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    try {
                        coSlice.at(-(Math.abs(sliceSize) + 1));
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + -(sliceSize + 1) + ")");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    for (int i = 1; i <= TEST_COLUMNS.length; i++) {
                        if (sliceSize > 0 && i >= coIndex && i < coIndex + sliceSize)
                            // Skip valid columns
                            continue;
                        if (sliceSize < 0 && i < coIndex && i >= coIndex + sliceSize)
                            // Skip valid columns
                            continue;
                        try {
                            coSlice.at(TEST_COLUMNS[i - 1]);
                            fail("Expected NoSuchElementException when calling" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(\"" + TEST_COLUMNS[i - 1] + "\")");
                        } catch (NoSuchElementException expected) {
                        /* Expected */
                        }
                    }
                }
            }
        }).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
    }
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Column(jdk.incubator.sql2.Result.Column) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collector(java.util.stream.Collector) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) Session(jdk.incubator.sql2.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Column(jdk.incubator.sql2.Result.Column) NoSuchElementException(java.util.NoSuchElementException) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 2 with Column

use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle.

the class RowOperationTest method testInvalidSlice.

@Test
public void testInvalidSlice() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger rowCount = new AtomicInteger();
        se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
            int rowIndex = rowCount.getAndIncrement();
            assertEquals(rowIndex, rc.rowNumber());
            assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
            int coIndex = 0;
            for (Column co : rc) {
                coIndex++;
                assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
                // From the current column index, test the invalid ranges.
                try {
                    co.slice(-coIndex);
                    fail("No exception thrown at call to slice(" + (-coIndex) + ")" + " from column index: " + coIndex);
                } catch (NoSuchElementException expected) {
                /* Expected */
                }
                try {
                    co.slice(1 + TEST_COLUMNS.length - (coIndex - 1));
                    fail("No exception thrown at call to slice(" + (-coIndex) + ")" + " from column index: " + coIndex);
                } catch (NoSuchElementException expected) {
                /* Expected */
                }
                try {
                    co.slice(0);
                    fail("No exception thrown at call to slice(0)" + " from column index: " + coIndex);
                } catch (NoSuchElementException expected) {
                /* Expected */
                }
            }
        }).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
    }
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Column(jdk.incubator.sql2.Result.Column) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collector(java.util.stream.Collector) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) Session(jdk.incubator.sql2.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Column(jdk.incubator.sql2.Result.Column) NoSuchElementException(java.util.NoSuchElementException) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 3 with Column

use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.

the class RowOperationTest method testInvalidAt.

@Test
public void testInvalidAt() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger rowCount = new AtomicInteger();
        se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
            int rowIndex = rowCount.getAndIncrement();
            assertEquals(rowIndex, rc.rowNumber());
            assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
            try {
                rc.at(TEST_COLUMNS.length + 1);
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at(0);
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at(-(TEST_COLUMNS.length + 1));
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            try {
                rc.at("z");
                fail("Expected NoSuchElementException");
            } catch (NoSuchElementException expected) {
            /* Expected */
            }
            int coIndex = 0;
            for (Column co : rc) {
                coIndex++;
                assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
                for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
                    if (sliceSize == 0)
                        continue;
                    Column coSlice = co.slice(sliceSize);
                    try {
                        coSlice.at(Math.abs(sliceSize) + 1);
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + (sliceSize + 1) + ")");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    try {
                        coSlice.at(0);
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(0)");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    try {
                        coSlice.at(-(Math.abs(sliceSize) + 1));
                        fail("Expected NoSuchElementException" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(" + -(sliceSize + 1) + ")");
                    } catch (NoSuchElementException expected) {
                    /* Expected */
                    }
                    for (int i = 1; i <= TEST_COLUMNS.length; i++) {
                        if (sliceSize > 0 && i >= coIndex && i < coIndex + sliceSize)
                            // Skip valid columns
                            continue;
                        if (sliceSize < 0 && i < coIndex && i >= coIndex + sliceSize)
                            // Skip valid columns
                            continue;
                        try {
                            coSlice.at(TEST_COLUMNS[i - 1]);
                            fail("Expected NoSuchElementException when calling" + " rc.at(" + coIndex + ")" + ".slice(" + sliceSize + ")" + ".at(\"" + TEST_COLUMNS[i - 1] + "\")");
                        } catch (NoSuchElementException expected) {
                        /* Expected */
                        }
                    }
                }
            }
        }).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
    }
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Column(jdk.incubator.sql2.Result.Column) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collector(java.util.stream.Collector) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) Session(jdk.incubator.sql2.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Column(jdk.incubator.sql2.Result.Column) NoSuchElementException(java.util.NoSuchElementException) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 4 with Column

use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.

the class RowOperationTest method testOffsetIteration.

@Test
public void testOffsetIteration() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger rowCount = new AtomicInteger();
        se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
            int rowIndex = rowCount.getAndIncrement();
            assertEquals(rowIndex, rc.rowNumber());
            assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
            for (int offset = 1; offset <= TEST_COLUMNS.length; offset++) {
                int count = 0;
                Column prev = null;
                for (Column col : rc.at(offset)) {
                    validateColumn(rowIndex, col, offset + count, 0, TEST_COLUMNS.length);
                    assertFalse(col == rc);
                    assertFalse(col == prev);
                    assertEquals(offset, rc.index());
                    prev = col;
                    count++;
                }
                assertEquals(1 + (TEST_COLUMNS.length - offset), count);
            }
        }).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
    }
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Column(jdk.incubator.sql2.Result.Column) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collector(java.util.stream.Collector) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) Session(jdk.incubator.sql2.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Column(jdk.incubator.sql2.Result.Column) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 5 with Column

use of jdk.incubator.sql2.Result.Column in project oracle-db-examples by oracle-samples.

the class RowOperationTest method testColumnSlice.

@Test
public void testColumnSlice() throws Exception {
    try (DataSource ds = getDataSource();
        Session se = ds.getSession()) {
        AtomicInteger rowCount = new AtomicInteger();
        se.rowOperation("SELECT * FROM " + TEST_TABLE).collect(ArrayList<String>::new, (ls, rc) -> {
            int rowIndex = rowCount.getAndIncrement();
            assertEquals(rowIndex, rc.rowNumber());
            assertEquals(TEST_COLUMNS.length - 1, rc.numberOfValuesRemaining());
            // valid slice sizes
            for (int sliceSize = 0; sliceSize <= TEST_COLUMNS.length; sliceSize++) {
                if (sliceSize == 0)
                    continue;
                Column sliceSequence = rc.slice(sliceSize);
                int sliceIndex = 0;
                for (Column sliceCo : sliceSequence) {
                    validateColumn(rowIndex, sliceCo, ++sliceIndex, 0, sliceSize);
                }
            }
            // From each column index, test the full range of valid slice
            // sizes.
            int coIndex = 0;
            for (Column co : rc) {
                coIndex++;
                assertEquals(TEST_COLUMNS.length - coIndex, co.numberOfValuesRemaining());
                for (int sliceSize = (1 - coIndex); sliceSize <= TEST_COLUMNS.length - (coIndex - 1); sliceSize++) {
                    if (sliceSize == 0)
                        continue;
                    Column sliceSequence = co.slice(sliceSize);
                    assertEquals(Math.abs(sliceSize) - 1, sliceSequence.numberOfValuesRemaining());
                    // The absolute index of the first column in the sequence.
                    int absStartIndex = (sliceSize < 0 ? (coIndex + sliceSize) : coIndex);
                    int sliceIndex = 0;
                    for (Column sliceCo : sliceSequence) {
                        sliceIndex++;
                        validateColumn(rowIndex, sliceCo, sliceIndex, absStartIndex - 1, Math.abs(sliceSize));
                    }
                    assertEquals(Math.abs(sliceSize), sliceIndex);
                }
            }
        }).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
    }
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Column(jdk.incubator.sql2.Result.Column) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) TestConfig(com.oracle.adbaoverjdbc.test.TestConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ForkJoinPool(java.util.concurrent.ForkJoinPool) Collector(java.util.stream.Collector) Assert(org.junit.Assert) NoSuchElementException(java.util.NoSuchElementException) Session(jdk.incubator.sql2.Session) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Column(jdk.incubator.sql2.Result.Column) DataSource(jdk.incubator.sql2.DataSource) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Aggregations

TestConfig (com.oracle.adbaoverjdbc.test.TestConfig)10 ArrayList (java.util.ArrayList)10 NoSuchElementException (java.util.NoSuchElementException)10 ForkJoinPool (java.util.concurrent.ForkJoinPool)10 TimeUnit (java.util.concurrent.TimeUnit)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Collector (java.util.stream.Collector)10 AdbaType (jdk.incubator.sql2.AdbaType)10 DataSource (jdk.incubator.sql2.DataSource)10 Column (jdk.incubator.sql2.Result.Column)10 Session (jdk.incubator.sql2.Session)10 AfterClass (org.junit.AfterClass)10 Assert (org.junit.Assert)10 BeforeClass (org.junit.BeforeClass)10 Test (org.junit.Test)10