Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/actions/run-uc-unit-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
Leave 'false' for published Spark.
required: false
default: 'false'
test-database:
description: Database the tests run on (default H2).
required: false
default: 'H2'

runs:
using: composite
Expand Down Expand Up @@ -69,6 +73,8 @@ runs:

- name: Run tests with coverage
shell: bash
env:
UC_TEST_DATABASE: ${{ inputs.test-database }}
run: |
if [[ "${{ inputs.validation-mode }}" == "spark-tests" ]]; then
echo "Running spark connector tests"
Expand All @@ -79,6 +85,6 @@ runs:
fi

- name: Run license check
if: inputs.validation-mode == 'all-tests'
if: inputs.validation-mode == 'all-tests' && inputs.test-database == 'H2'
shell: bash
run: build/sbt -DsparkVersion=${{ inputs.spark-version }} -DdeltaVersion=$DELTA_VERSION licenseCheck
13 changes: 12 additions & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ jobs:
# Build a human-readable job name from the matrix entry, e.g.:
# "All tests (Spark 4.0.0, Delta 4.3.1)"
# "[Non Blocking] Spark tests (Spark 4.2.0, Delta master-SNAPSHOT)"
# "All tests (Spark 4.0.0, Delta 4.3.1, POSTGRES_18)"
name: >-
${{ matrix.non-blocking && '[Non Blocking]' || '' }}
${{ matrix.validation-mode == 'spark-tests' && 'Spark tests' || 'All tests' }}
(Spark ${{ matrix.spark-version }}${{ matrix.delta-version != '' && format(', Delta {0}', matrix.delta-version) || '' }})
(Spark ${{ matrix.spark-version }}${{ matrix.delta-version != '' && format(', Delta {0}', matrix.delta-version) || '' }}${{ matrix.test-database && format(', {0}', matrix.test-database) || '' }})
continue-on-error: ${{ matrix.non-blocking || false }}
strategy:
fail-fast: false
Expand All @@ -59,6 +60,13 @@ jobs:
validation-mode: "all-tests"
non-blocking: false
spark-source-build: false
- spark-version: "4.0.0"
delta-version: "4.3.1"
# Primary combo on PostgreSQL 18: every test project runs on PostgreSQL.
validation-mode: "all-tests"
test-database: "POSTGRES_18"
non-blocking: false
spark-source-build: false
- spark-version: "4.1.0"
delta-version: "4.3.1"
validation-mode: "spark-tests"
Expand Down Expand Up @@ -92,4 +100,7 @@ jobs:
spark-version: ${{ matrix.spark-version }}
delta-version: ${{ matrix.delta-version }}
validation-mode: ${{ matrix.validation-mode }}
# Rows without test-database pass an empty string, not the action's default, so fall back
# to H2 here; an empty value would skip the license check and fail the database lookup.
test-database: ${{ matrix.test-database || 'H2' }}
use-spark-source-cache: ${{ matrix.spark-source-build }}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import io.unitycatalog.server.exception.ErrorCode;
import io.unitycatalog.server.exception.TransactionRollbackException;
import io.unitycatalog.server.persist.dao.DeltaCommitDAO;
import io.unitycatalog.server.persist.dao.StagingTableDAO;
import io.unitycatalog.server.testdatabase.SupportedDatabase;
import io.unitycatalog.server.testdatabase.TestDatabase;
import io.unitycatalog.server.testdatabase.TestDatabases;
import io.unitycatalog.server.utils.ServerProperties;
Expand All @@ -28,6 +30,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Random;
import java.util.UUID;
import java.util.stream.Stream;
import org.hibernate.Session;
Expand Down Expand Up @@ -435,9 +438,9 @@ static Stream<Arguments> databaseErrors() {
}

/**
* Tests for the isolation level code path using a real H2 database. These verify that the
* rollback() call before setTransactionIsolation() correctly flushes stale implicit transactions
* from pooled connections, ensuring REPEATABLE_READ gets a fresh MVCC snapshot.
* Tests for the isolation level code path using a real database. These verify that the rollback()
* call before setTransactionIsolation() correctly flushes stale implicit transactions from pooled
* connections, ensuring REPEATABLE_READ gets a fresh MVCC snapshot.
*/
@Nested
public class IsolationLevelWithRealDatabaseTest {
Expand Down Expand Up @@ -491,7 +494,8 @@ public void testIsolationLevelIsSetAndRestored() {
"test",
true);

// Original isolation level should have been restored (H2 default is READ_COMMITTED)
// Original isolation level should have been restored (H2 and PostgreSQL default to
// READ_COMMITTED)
assertThat(isolationAfter[0]).isEqualTo(Connection.TRANSACTION_READ_COMMITTED);
}

Expand Down Expand Up @@ -558,4 +562,81 @@ private DeltaCommitDAO buildCommitDAO(UUID tableId, long version) {
.build();
}
}

/** Tests that a database error is reported with the error code it maps to, on a real database. */
@Nested
public class DatabaseErrorWithRealDatabaseTest {

private static SessionFactory realSessionFactory;
private static TestDatabase testDatabase;

@BeforeAll
public static void setUp() {
testDatabase = TestDatabases.newDatabase();
realSessionFactory =
testDatabase
.openHibernateConfigurator(new ServerProperties(new Properties()))
.getSessionFactory();
}

@AfterAll
public static void tearDown() {
testDatabase.close();
}

/**
* PostgreSQL limits a btree index entry to 2,704 bytes. A longer staging location fails the
* insert into idx_staging_location, which the request caused, so it is INVALID_ARGUMENT. H2 has
* no such limit, so the insert succeeds there.
*/
@Test
public void testValueOverIndexLimitIsInvalidArgument() {
Comment thread
shba24 marked this conversation as resolved.
Resolved
boolean overIndexLimit =
switch (SupportedDatabase.selected()) {
case H2 -> false;
case POSTGRES_18 -> true;
};
StagingTableDAO stagingTableDAO = new StagingTableDAO();
stagingTableDAO.setDefaultFields();
stagingTableDAO.setId(UUID.randomUUID());
stagingTableDAO.setName("staging_table");
// 1,917 characters and 3,817 bytes: fits varchar(2048) but not an index entry.
stagingTableDAO.setStagingLocation("s3://test-bucket/" + randomTwoByteCharacters(1900));

Throwable failure =
catchThrowable(
() ->
TransactionManager.executeWithTransaction(
realSessionFactory,
session -> {
session.persist(stagingTableDAO);
return null;
},
"Error creating staging table",
/* readOnly= */ false));

if (overIndexLimit) {
assertThat(failure)
.isInstanceOf(BaseException.class)
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.INVALID_ARGUMENT)
.hasMessageContaining("index row size");
} else {
assertThat(failure).isNull();
}
}

/**
* Returns random letters that each take 2 bytes in UTF-8. They are random because PostgreSQL
* compresses an index entry before it checks the size.
*/
private static String randomTwoByteCharacters(int count) {
// Latin Extended-A, Latin Extended-B and IPA Extensions: U+0100 to U+02AF.
Random random = new Random(/* seed= */ 0);
StringBuilder characters = new StringBuilder();
for (int i = 0; i < count; i++) {
characters.append((char) (0x0100 + random.nextInt(0x02B0 - 0x0100)));
}
return characters.toString();
}
}
}

This file was deleted.

Loading