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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations