コード例 #1
0
 @Test(expected = ResourceTransactionException.class)
 public void testResourceTimeoutInvalidatesTransaction() throws Exception {
   ResourceTransaction transaction = resourceFactory.getTransaction();
   transaction.setTransactionTimeout(2);
   transaction.begin();
   Thread.sleep(3000);
   transaction.commit();
 }
コード例 #2
0
 @Test
 public void testResourceTransactionSucceeds() throws Exception {
   ResourceTransaction transaction = resourceFactory.getTransaction();
   Assert.assertFalse(transaction.isStarted());
   transaction.begin();
   Assert.assertTrue(transaction.isStarted());
   Thread.sleep(1000);
   transaction.commit();
   Assert.assertFalse(transaction.isStarted());
 }
コード例 #3
0
 @Test
 @SuppressWarnings("unchecked")
 public void testResourceTransactionCommit() throws IOException {
   File tempDir = OperatingSystemUtils.createTempDir();
   File file = createTempFile(tempDir, false);
   ResourceTransaction transaction = resourceFactory.getTransaction();
   Assert.assertNotNull(transaction);
   Assert.assertFalse(transaction.isStarted());
   transaction.begin();
   Assert.assertTrue(transaction.isStarted());
   FileResource<?> fileResource = resourceFactory.create(FileResource.class, file);
   Assert.assertNotNull(fileResource);
   fileResource.setContents("Hello World");
   transaction.commit();
   Assert.assertTrue(fileResource.exists());
   Assert.assertEquals("Hello World", fileResource.getContents());
 }
コード例 #4
0
 @Test
 @SuppressWarnings("unchecked")
 public void testResourceChangeSet() throws IOException {
   File tempDir = OperatingSystemUtils.createTempDir();
   File file = createTempFile(tempDir, true);
   ResourceTransaction transaction = resourceFactory.getTransaction();
   Assert.assertNotNull(transaction);
   Assert.assertFalse(transaction.isStarted());
   transaction.begin();
   Assert.assertTrue(transaction.isStarted());
   FileResource<?> fileResource = resourceFactory.create(FileResource.class, file);
   Assert.assertNotNull(fileResource);
   fileResource.setContents("Hello World");
   Assert.assertEquals("Hello World", fileResource.getContents());
   Collection<ResourceEvent> changeSet = transaction.getChangeSet();
   Assert.assertEquals(3, changeSet.size());
   Iterator<ResourceEvent> iterator = changeSet.iterator();
   // Created the file
   {
     ResourceEvent event = iterator.next();
     Assert.assertThat(event, is(instanceOf(ResourceCreated.class)));
     Assert.assertEquals(fileResource, event.getResource());
   }
   {
     ResourceEvent event = iterator.next();
     // Modified the Directory
     Assert.assertThat(event, is(instanceOf(ResourceModified.class)));
     Assert.assertThat(event.getResource(), is(instanceOf(DirectoryResource.class)));
   }
   {
     ResourceEvent event = iterator.next();
     // Modified the File resource
     Assert.assertThat(event, is(instanceOf(ResourceModified.class)));
     Assert.assertEquals(fileResource, event.getResource());
   }
   Assert.assertFalse(file.exists());
   Assert.assertTrue(fileResource.exists());
   transaction.commit();
   Assert.assertTrue(fileResource.exists());
   Assert.assertTrue(file.exists());
   Assert.assertEquals("Hello World", fileResource.getContents());
 }
コード例 #5
0
 @After
 public void tearDown() {
   ResourceTransaction transaction = resourceFactory.getTransaction();
   if (transaction.isStarted()) transaction.rollback();
 }
コード例 #6
0
 @Test(expected = ResourceTransactionException.class)
 public void testResourceTimeout() {
   ResourceTransaction transaction = resourceFactory.getTransaction();
   transaction.setTransactionTimeout(-100);
 }