Guest User

Untitled

a guest
Oct 9th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. import static org.junit.Assert.fail;
  2. import static org.junit.Assert.assertEquals;
  3.  
  4. import java.util.Date;
  5.  
  6. import org.junit.Before;
  7. import org.junit.Test;
  8.  
  9. import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal;
  10. import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
  11. import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
  12. import com.orientechnologies.orient.core.metadata.schema.OType;
  13. import com.orientechnologies.orient.core.record.impl.ODocument;
  14.  
  15. /**
  16. * @author Salvatore Piccione (TXT e-solutions SpA - salvatore.piccione AT network.txtgroup.com)
  17. *
  18. */
  19. public class LogTest {
  20.  
  21. private ODatabaseDocumentPool dbPool = null;
  22.  
  23. private static final String databaseURL = "remote:localhost/test-log4j-storage";
  24. private static final String username = "admin";
  25. private static final String password = "admin";
  26.  
  27. @Before
  28. public void init () {
  29. if (dbPool == null)
  30. this.definePool();
  31. }
  32.  
  33. @Test
  34. public void testPool () throws Exception {
  35. for (int i = 0; i < 10; i++) {
  36. ODatabaseDocumentTx dbConnection = dbPool.acquire(databaseURL, username, password);
  37. ODatabaseRecordThreadLocal.INSTANCE.set(dbConnection);
  38. ODocument doc = new ODocument("TestClass");
  39. doc.field(PropertyNames.MESSAGE, "just a string " + i, OType.STRING);
  40. doc.field(PropertyNames.TIMESTAMP,new Date());
  41. doc.save();
  42. dbConnection.close();
  43. Thread.sleep(1000);
  44. }
  45. }
  46.  
  47. private void definePool () {
  48. dbPool = ODatabaseDocumentPool.global();
  49. dbPool.setup(1, 5);
  50. assertEquals(5,dbPool.getMaxSize());
  51. ODatabaseDocumentTx dbConnection = dbPool.acquire(databaseURL, username, password);
  52. ODatabaseRecordThreadLocal.INSTANCE.set(dbConnection);
  53. dbConnection.getMetadata().getSchema().getOrCreateClass("TestClass");
  54. dbConnection.close();
  55. }
  56. }
Add Comment
Please, Sign In to add comment