comparison test/org/tmatesoft/hg/test/TestCommit.java @ 623:fedc54356091

Update tests for Windows; TestCommit: use copy of a repo (not clone) to preserve old timestamps
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 20 May 2013 18:35:13 +0200
parents 99ad1e3a4e4d
children 507602cb4fb3
comparison
equal deleted inserted replaced
622:4e6179bde4fc 623:fedc54356091
378 errorCollector.assertEquals("Read from fresh HgDataFile instance", newFileContent, read2.toArray()); 378 errorCollector.assertEquals("Read from fresh HgDataFile instance", newFileContent, read2.toArray());
379 } 379 }
380 380
381 @Test 381 @Test
382 public void testRollback() throws Exception { 382 public void testRollback() throws Exception {
383 File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-rollback", false); 383 // Important: copy, not a clone of a repo to ensure old timestamps
384 // on repository files. Otherwise, there're chances transacition.rollback()
385 // would happen the very second (when fs timestamp granularity is second)
386 // repository got cloned, and RevlogChangeMonitor won't notice the file change
387 // (timestamp is the same, file size increased (CommitFacility) and decreased
388 // on rollback back to memorized value), and subsequent hgRepo access would fail
389 // trying to read more (due to Revlog#revisionAdded) revisions than there are in
390 // the store file.
391 // With copy and original timestamps we pretend commit happens to an existing repository
392 // in a regular manner (it's unlikely to have commits within the same second in a real life)
393 // XXX Note, once we have more robust method to detect file changes (e.g. Java7), this
394 // approach shall be abandoned.
395 File repoLoc = RepoUtils.copyRepoToTempLocation("log-1", "test-commit-rollback");
384 final Path newFilePath = Path.create("xx"); 396 final Path newFilePath = Path.create("xx");
385 final File newFile = new File(repoLoc, newFilePath.toString()); 397 final File newFile = new File(repoLoc, newFilePath.toString());
386 RepoUtils.createFile(newFile, "xyz"); 398 RepoUtils.createFile(newFile, "xyz");
387 HgRepository hgRepo = new HgLookup().detect(repoLoc); 399 HgRepository hgRepo = new HgLookup().detect(repoLoc);
388 HgDataFile dfB = hgRepo.getFileNode("b"); 400 HgDataFile dfB = hgRepo.getFileNode("b");
409 cf.add(dfB, new FileContentSupplier(hgRepo, modifiedFile)); 421 cf.add(dfB, new FileContentSupplier(hgRepo, modifiedFile));
410 cf.forget(dfD); 422 cf.forget(dfD);
411 cf.branch("another-branch"); 423 cf.branch("another-branch");
412 Transaction tr = newTransaction(hgRepo); 424 Transaction tr = newTransaction(hgRepo);
413 Nodeid commitRev = cf.commit("Commit to fail", tr); 425 Nodeid commitRev = cf.commit("Commit to fail", tr);
414 // with 1 second timestamp granularity, HgChangelog doesn't
415 // recognize the fact the underlying file got changed twice within
416 // a second, doesn't discard new revision obtained via revisionAdded,
417 // and eventually fails trying to read more revisions than there're in the file
418 Thread.sleep(1000); // FIXME this is a hack to make test pass
419 tr.rollback(); 426 tr.rollback();
420 // 427 //
421 errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision()); 428 errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());
422 errorCollector.assertEquals(lastManifestRev, hgRepo.getManifest().getLastRevision()); 429 errorCollector.assertEquals(lastManifestRev, hgRepo.getManifest().getLastRevision());
423 errorCollector.assertEquals(DEFAULT_BRANCH_NAME, DirstateReader.readBranch(Internals.getInstance(hgRepo))); 430 errorCollector.assertEquals(DEFAULT_BRANCH_NAME, DirstateReader.readBranch(Internals.getInstance(hgRepo)));