* with the file persistence adapter.
*/
public void testFragmentReplicationUpdateDelete() throws Exception
{
Metadata metadata = loadMetadata("filestoragefragment");
InvocationContext context = new InvocationContext(metadata);
try
{
ThreadContextHolder.setContext(context);
File mainDir = TempFileUtil.makeTemporaryDirectory(getName());
File tempDir = new File(mainDir, "temp");
File dataDir = new File(mainDir, "data");
File jrnlDir = new File(mainDir, "journal");
File tempDir1 = new File(mainDir, "temp1");
File dataDir1 = new File(mainDir, "data1");
File jrnlDir1 = new File(mainDir, "journal1");
assertTrue(tempDir.mkdir());
assertTrue(dataDir.mkdir());
assertTrue(jrnlDir.mkdir());
assertTrue(tempDir1.mkdir());
assertTrue(dataDir1.mkdir());
assertTrue(jrnlDir1.mkdir());
DataSource ds = metadata.getDataSource("TestFilePersistenceDataSource");
assertEquals(2, ds.getFragmentCount());
FileDataSourceFragment defaultFrag = (FileDataSourceFragment)ds.getDefaultFragment();
FileDataSourceFragment fragment1 = (FileDataSourceFragment)ds.getFragment("fragment1");
defaultFrag.debugSettings(dataDir.getAbsolutePath(),
tempDir.getAbsolutePath(),
jrnlDir.getAbsolutePath());
fragment1.debugSettings(dataDir1.getAbsolutePath(),
tempDir1.getAbsolutePath(),
jrnlDir1.getAbsolutePath());
// Create it
assertNull(context.beginTransaction());
Metaclass testFPA = metadata.getMetaclass("TestFPA");
Instance a = (Instance)testFPA.invoke("new");
a.setValue("data", new Binary("Creation (\u4e2d\u6587) data.".getBytes("utf-8")));
// Replicate
context.getUnitOfWork().addReplicationFragment(a, "fragment1");
commit(context);
OID oidA = a.getOID();
String sOidName = (String)oidA.getValue(0);
// Verify
File defaultFile = FileManagedConnection.splitNameToSubdirs(dataDir, sOidName, 3, 2, false);
assertTrue(defaultFile.exists());
assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(defaultFile));
File fragment1File = FileManagedConnection.splitNameToSubdirs(dataDir1, sOidName, 3, 2, false);
assertTrue(fragment1File.exists());
assertEquals("Creation (\u4e2d\u6587) data.", readFileToString(fragment1File));
// Update it
assertNull(context.beginTransaction());
a.setValue("data", new Binary("Modified data.\nModified.".getBytes("utf-8")));
// Replication
context.getUnitOfWork().addReplicationFragment(a, "fragment1");
commit(context);
// Verify
assertTrue(defaultFile.exists());
assertEquals("Modified data.\nModified.", readFileToString(defaultFile));
assertTrue(fragment1File.exists());
assertEquals("Modified data.\nModified.", readFileToString(fragment1File));
// Delete it
assertNull(context.beginTransaction());
a.invoke("delete");
// Replication
context.getUnitOfWork().addReplicationFragment(a, "fragment1");
commit(context);
//Verify
assertFalse(defaultFile.exists());
assertFalse(fragment1File.exists());
}
finally
{
context.complete(false);
ThreadContextHolder.setContext(null);
}
}