Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.fail;
- import static org.junit.Assert.assertEquals;
- import java.util.Date;
- import org.junit.Before;
- import org.junit.Test;
- import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
- import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
- import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
- import com.orientechnologies.orient.core.metadata.schema.OType;
- import com.orientechnologies.orient.core.record.impl.ODocument;
- /**
- * @author Salvatore Piccione (TXT e-solutions SpA - salvatore.piccione AT network.txtgroup.com)
- *
- */
- public class LogTest {
- private ODatabaseDocumentPool dbPool = null;
- private static final String databaseURL = "remote:localhost/test-log4j-storage";
- private static final String username = "admin";
- private static final String password = "admin";
- @Before
- public void init () {
- if (dbPool == null)
- this.definePool();
- }
- @Test
- public void testPool () throws Exception {
- for (int i = 0; i < 10; i++) {
- ODatabaseDocumentTx dbConnection = dbPool.acquire(databaseURL, username, password);
- ODatabaseRecordThreadLocal.INSTANCE.set(dbConnection);
- ODocument doc = new ODocument("TestClass");
- doc.field(PropertyNames.MESSAGE, "just a string " + i, OType.STRING);
- doc.field(PropertyNames.TIMESTAMP,new Date());
- doc.save();
- dbConnection.close();
- Thread.sleep(1000);
- }
- }
- private void definePool () {
- dbPool = ODatabaseDocumentPool.global();
- dbPool.setup(1, 5);
- assertEquals(5,dbPool.getMaxSize());
- ODatabaseDocumentTx dbConnection = dbPool.acquire(databaseURL, username, password);
- ODatabaseRecordThreadLocal.INSTANCE.set(dbConnection);
- dbConnection.getMetadata().getSchema().getOrCreateClass("TestClass");
- dbConnection.close();
- }
- }
Add Comment
Please, Sign In to add comment