Search in sources :

Example 1 with Transaction

use of com.spotify.protoman.registry.storage.SchemaStorage.Transaction in project protoman by spotify.

the class GcsSchemaStorageIT method testTransactions.

@Test
public void testTransactions() {
    final long snapshot0;
    try (final Transaction tx = schemaStorage.open()) {
        snapshot0 = tx.getLatestSnapshotVersion();
    }
    // add file1
    final long snapshot1;
    try (final Transaction tx = schemaStorage.open()) {
        tx.storeFile(schemaFile1);
        snapshot1 = tx.commit();
    }
    // add package version for pkg1
    final long snapshot2;
    try (final Transaction tx = schemaStorage.open()) {
        tx.storePackageVersion("pkg1", SchemaVersion.create("1", 0, 0));
        snapshot2 = tx.commit();
    }
    // add file2 and change package version for pkg1 and add package version for pkg2
    final long snapshot3;
    try (final Transaction tx = schemaStorage.open()) {
        tx.storeFile(schemaFile2);
        tx.storePackageVersion("pkg1", SchemaVersion.create("2", 0, 0));
        tx.storePackageVersion("pkg2", SchemaVersion.create("0", 1, 0));
        snapshot3 = tx.commit();
    }
    // delete a file
    final long snapshot4;
    try (final Transaction tx = schemaStorage.open()) {
        tx.deleteFile(schemaFile2.path());
        snapshot4 = tx.commit();
    }
    // delete a file and update package version without committing transaction
    try (final Transaction tx = schemaStorage.open()) {
        tx.storeFile(schemaFile2);
        tx.storePackageVersion("pkg1", SchemaVersion.create("2", 0, 0));
        tx.storePackageVersion("pkg2", SchemaVersion.create("0", 1, 0));
    // no commit
    }
    final long snapshot5;
    try (final Transaction tx = schemaStorage.open()) {
        snapshot5 = tx.getLatestSnapshotVersion();
    }
    assertThat(schemaFiles(snapshot0), equalTo(ImmutableSet.of()));
    assertThat(packageVersions(snapshot0), equalTo(ImmutableMap.of()));
    assertThat(snapshot1, is(greaterThan(snapshot0)));
    assertThat(schemaFiles(snapshot1), equalTo(ImmutableSet.of(schemaFile1)));
    assertThat(packageVersions(snapshot1), equalTo(ImmutableMap.of()));
    assertThat(snapshot2, is(greaterThan(snapshot1)));
    assertThat(schemaFiles(snapshot2), equalTo(ImmutableSet.of(schemaFile1)));
    assertThat(packageVersions(snapshot2), equalTo(ImmutableMap.of("pkg1", SchemaVersion.create("1", 0, 0))));
    assertThat(snapshot3, is(greaterThan(snapshot2)));
    assertThat(schemaFiles(snapshot3), equalTo(ImmutableSet.of(schemaFile1, schemaFile2)));
    assertThat(packageVersions(snapshot3), equalTo(ImmutableMap.of("pkg1", SchemaVersion.create("2", 0, 0), "pkg2", SchemaVersion.create("0", 1, 0))));
    assertThat(snapshot4, is(greaterThan(snapshot3)));
    assertThat(schemaFiles(snapshot4), equalTo(ImmutableSet.of(schemaFile1)));
    assertThat(packageVersions(snapshot4), equalTo(ImmutableMap.of("pkg1", SchemaVersion.create("2", 0, 0), "pkg2", SchemaVersion.create("0", 1, 0))));
    assertThat(snapshot5, equalTo(snapshot4));
    assertThat(schemaFiles(snapshot4), equalTo(ImmutableSet.of(schemaFile1)));
    assertThat(packageVersions(snapshot4), equalTo(ImmutableMap.of("pkg1", SchemaVersion.create("2", 0, 0), "pkg2", SchemaVersion.create("0", 1, 0))));
}
Also used : Transaction(com.spotify.protoman.registry.storage.SchemaStorage.Transaction) Test(org.junit.Test)

Example 2 with Transaction

use of com.spotify.protoman.registry.storage.SchemaStorage.Transaction in project protoman by spotify.

the class GcsSchemaStorageIT method useOfAlreadyCommittedTransactionThrows_get.

@Test(expected = IllegalStateException.class)
public void useOfAlreadyCommittedTransactionThrows_get() {
    try (final Transaction tx = schemaStorage.open()) {
        tx.commit();
        tx.getLatestSnapshotVersion();
    }
}
Also used : Transaction(com.spotify.protoman.registry.storage.SchemaStorage.Transaction) Test(org.junit.Test)

Example 3 with Transaction

use of com.spotify.protoman.registry.storage.SchemaStorage.Transaction in project protoman by spotify.

the class GcsSchemaStorageIT method useOfAlreadyCommittedTransactionThrows_commit.

@Test(expected = IllegalStateException.class)
public void useOfAlreadyCommittedTransactionThrows_commit() {
    try (final Transaction tx = schemaStorage.open()) {
        tx.commit();
        tx.commit();
    }
}
Also used : Transaction(com.spotify.protoman.registry.storage.SchemaStorage.Transaction) Test(org.junit.Test)

Example 4 with Transaction

use of com.spotify.protoman.registry.storage.SchemaStorage.Transaction in project protoman by spotify.

the class GcsSchemaStorageIT method testPackageVersion.

@Test
public void testPackageVersion() {
    final Optional<SchemaVersion> before;
    final Optional<SchemaVersion> after;
    try (final Transaction tx = schemaStorage.open()) {
        before = tx.getPackageVersion(tx.getLatestSnapshotVersion(), "pkg1");
    }
    // store pkg
    try (final Transaction tx = schemaStorage.open()) {
        tx.storePackageVersion("pkg1", SchemaVersion.create("1", 0, 0));
        tx.commit();
    }
    try (final Transaction tx = schemaStorage.open()) {
        after = tx.getPackageVersion(tx.getLatestSnapshotVersion(), "pkg1");
    }
    assertThat(before, is(Optional.empty()));
    assertThat(after, is(Optional.of(SchemaVersion.create("1", 0, 0))));
}
Also used : SchemaVersion(com.spotify.protoman.registry.SchemaVersion) Transaction(com.spotify.protoman.registry.storage.SchemaStorage.Transaction) Test(org.junit.Test)

Aggregations

Transaction (com.spotify.protoman.registry.storage.SchemaStorage.Transaction)4 Test (org.junit.Test)4 SchemaVersion (com.spotify.protoman.registry.SchemaVersion)1