Search in sources :

Example 1 with OSequenceLibrary

use of com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary in project orientdb by orientechnologies.

the class AbstractServerClusterSequenceTest method executeOrderedSequenceTest.

private void executeOrderedSequenceTest(final ODatabaseDocumentTx[] dbs, final String sequenceName) throws Exception {
    OSequenceLibrary seq1 = dbs[0].getMetadata().getSequenceLibrary();
    OSequenceLibrary seq2 = dbs[1].getMetadata().getSequenceLibrary();
    seq1.createSequence(sequenceName, SEQUENCE_TYPE.ORDERED, null);
    Assert.assertEquals(SEQUENCE_TYPE.ORDERED, seq1.getSequence(sequenceName).getSequenceType());
    Assert.assertNotNull("The sequence has not be propagated to the 2nd server", seq2.getSequence(sequenceName));
    ODatabaseRecordThreadLocal.INSTANCE.set(dbs[0]);
    Assert.assertEquals(0L, seq1.getSequence(sequenceName).current());
    ODatabaseRecordThreadLocal.INSTANCE.set(dbs[1]);
    Assert.assertEquals(0L, seq2.getSequence(sequenceName).current());
    Assert.assertEquals(1L, seq2.getSequence(sequenceName).next());
    ODatabaseRecordThreadLocal.INSTANCE.set(dbs[0]);
    Assert.assertEquals(2L, seq1.getSequence(sequenceName).next());
    Assert.assertEquals(3L, seq1.getSequence(sequenceName).next());
    ODatabaseRecordThreadLocal.INSTANCE.set(dbs[1]);
    Assert.assertEquals(0L, seq2.getSequence(sequenceName).reset());
    ODatabaseRecordThreadLocal.INSTANCE.set(dbs[0]);
    Assert.assertEquals(0L, seq1.getSequence(sequenceName).current());
    if (RUN_PARALLEL_SYNC_TEST) {
        executeParallelSyncTest(dbs, sequenceName, SEQUENCE_TYPE.ORDERED);
    }
}
Also used : OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)

Example 2 with OSequenceLibrary

use of com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary in project orientdb by orientechnologies.

the class SQLSequenceTest method testSequence.

private void testSequence(String sequenceName, OSequence.SEQUENCE_TYPE sequenceType) {
    OSequenceLibrary sequenceLibrary = database.getMetadata().getSequenceLibrary();
    database.command(new OCommandSQL("CREATE SEQUENCE " + sequenceName + " TYPE " + sequenceType)).execute();
    OSequenceException err = null;
    try {
        database.command(new OCommandSQL("CREATE SEQUENCE " + sequenceName + " TYPE " + sequenceType)).execute();
    } catch (OSequenceException se) {
        err = se;
    }
    Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating a second " + sequenceType.toString() + " sequences with same name doesn't throw an exception");
    // Doing it twice to check everything works after reset
    for (int i = 0; i < 2; ++i) {
        Assert.assertEquals(sequenceCurrent(sequenceName), 0L);
        Assert.assertEquals(sequenceNext(sequenceName), 1L);
        Assert.assertEquals(sequenceCurrent(sequenceName), 1L);
        Assert.assertEquals(sequenceNext(sequenceName), 2L);
        Assert.assertEquals(sequenceNext(sequenceName), 3L);
        Assert.assertEquals(sequenceNext(sequenceName), 4L);
        Assert.assertEquals(sequenceCurrent(sequenceName), 4L);
        Assert.assertEquals(sequenceReset(sequenceName), 0L);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)

Example 3 with OSequenceLibrary

use of com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary in project orientdb by orientechnologies.

the class SequenceTest method testSequence.

private void testSequence(String sequenceName, SEQUENCE_TYPE sequenceType) {
    OSequenceLibrary sequenceLibrary = database.getMetadata().getSequenceLibrary();
    OSequence seq = sequenceLibrary.createSequence(sequenceName, sequenceType, null);
    OSequenceException err = null;
    try {
        sequenceLibrary.createSequence(sequenceName, sequenceType, null);
    } catch (OSequenceException se) {
        err = se;
    }
    Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating a second " + sequenceType.toString() + " sequences with same name doesn't throw an exception");
    OSequence seqSame = sequenceLibrary.getSequence(sequenceName);
    Assert.assertEquals(seqSame, seq);
    // Doing it twice to check everything works after reset
    for (int i = 0; i < 2; ++i) {
        Assert.assertEquals(seq.next(), 1L);
        Assert.assertEquals(seq.current(), 1L);
        Assert.assertEquals(seq.next(), 2L);
        Assert.assertEquals(seq.next(), 3L);
        Assert.assertEquals(seq.next(), 4L);
        Assert.assertEquals(seq.current(), 4L);
        Assert.assertEquals(seq.reset(), 0L);
    }
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)

Example 4 with OSequenceLibrary

use of com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary in project orientdb by orientechnologies.

the class SequenceTest method testOrdered.

@Test
public void testOrdered() {
    OSequenceLibrary sequenceManager = database.getMetadata().getSequenceLibrary();
    OSequence seq = sequenceManager.createSequence("seqOrdered", SEQUENCE_TYPE.ORDERED, null);
    OSequenceException err = null;
    try {
        sequenceManager.createSequence("seqOrdered", SEQUENCE_TYPE.ORDERED, null);
    } catch (OSequenceException se) {
        err = se;
    }
    Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating two ordered sequences with same name doesn't throw an exception");
    OSequence seqSame = sequenceManager.getSequence("seqOrdered");
    Assert.assertEquals(seqSame, seq);
    testUsage(seq, FIRST_START);
    // 
    seq.updateParams(new OSequence.CreateParams().setStart(SECOND_START).setCacheSize(13));
    testUsage(seq, SECOND_START);
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) Test(org.testng.annotations.Test)

Example 5 with OSequenceLibrary

use of com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary in project orientdb by orientechnologies.

the class SQLSequenceTest method testFree.

@Test
public void testFree() {
    OSequenceLibrary sequenceManager = database.getMetadata().getSequenceLibrary();
    OSequence seq = sequenceManager.createSequence("seqSQLOrdered", OSequence.SEQUENCE_TYPE.ORDERED, null);
    OSequenceException err = null;
    try {
        sequenceManager.createSequence("seqSQLOrdered", OSequence.SEQUENCE_TYPE.ORDERED, null);
    } catch (OSequenceException se) {
        err = se;
    }
    Assert.assertTrue(err == null || err.getMessage().toLowerCase(Locale.ENGLISH).contains("already exists"), "Creating two ordered sequences with same name doesn't throw an exception");
    OSequence seqSame = sequenceManager.getSequence("seqSQLOrdered");
    Assert.assertEquals(seqSame, seq);
    testUsage(seq, FIRST_START);
    // 
    seq.updateParams(new OSequence.CreateParams().setStart(SECOND_START).setCacheSize(13));
    testUsage(seq, SECOND_START);
}
Also used : OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OSequence(com.orientechnologies.orient.core.metadata.sequence.OSequence) OSequenceLibrary(com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary) Test(org.testng.annotations.Test)

Aggregations

OSequenceLibrary (com.orientechnologies.orient.core.metadata.sequence.OSequenceLibrary)6 OSequenceException (com.orientechnologies.orient.core.exception.OSequenceException)4 OSequence (com.orientechnologies.orient.core.metadata.sequence.OSequence)3 Test (org.testng.annotations.Test)2 OException (com.orientechnologies.common.exception.OException)1 OCommandCacheSoftRefs (com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 OIndexManagerRemote (com.orientechnologies.orient.core.index.OIndexManagerRemote)1 OIndexManagerShared (com.orientechnologies.orient.core.index.OIndexManagerShared)1 OFunctionLibrary (com.orientechnologies.orient.core.metadata.function.OFunctionLibrary)1 OFunctionLibraryImpl (com.orientechnologies.orient.core.metadata.function.OFunctionLibraryImpl)1 OFunctionLibraryProxy (com.orientechnologies.orient.core.metadata.function.OFunctionLibraryProxy)1 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)1 OSchemaProxy (com.orientechnologies.orient.core.metadata.schema.OSchemaProxy)1 OSchemaShared (com.orientechnologies.orient.core.metadata.schema.OSchemaShared)1 OSecurity (com.orientechnologies.orient.core.metadata.security.OSecurity)1 OSecurityProxy (com.orientechnologies.orient.core.metadata.security.OSecurityProxy)1