use of org.jboss.byteman.contrib.bmunit.BMRules in project hibernate-orm by hibernate.
the class CriteriaLockingTest method testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue.
@Test
@BMRules(rules = { @BMRule(targetClass = "org.hibernate.dialect.Dialect", targetMethod = "useFollowOnLocking", action = "return true", name = "H2DialectUseFollowOnLocking") })
public void testSetLockModeDifferentFromNONELogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
buildSessionFactory();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000444");
final Session s = openSession();
final Transaction tx = s.beginTransaction();
Item item = new Item();
item.name = "ZZZZ";
s.persist(item);
s.flush();
Criteria criteria = s.createCriteria(Item.class).setLockMode(LockMode.OPTIMISTIC);
criteria.list();
tx.rollback();
s.close();
releaseSessionFactory();
assertTrue(triggerable.wasTriggered());
}
use of org.jboss.byteman.contrib.bmunit.BMRules in project hibernate-orm by hibernate.
the class CriteriaLockingTest method testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue.
@Test
@BMRules(rules = { @BMRule(targetClass = "org.hibernate.dialect.Dialect", targetMethod = "useFollowOnLocking", action = "return true", name = "H2DialectUseFollowOnLocking") })
public void testSetLockModeNONEDoNotLogAWarnMessageWhenTheDialectUseFollowOnLockingIsTrue() {
buildSessionFactory();
Triggerable triggerable = logInspection.watchForLogMessages("HHH000444");
final Session s = openSession();
final Transaction tx = s.beginTransaction();
Item item = new Item();
item.name = "ZZZZ";
s.persist(item);
s.flush();
Criteria criteria = s.createCriteria(Item.class).setLockMode(LockMode.NONE);
criteria.list();
tx.rollback();
s.close();
releaseSessionFactory();
assertFalse(triggerable.wasTriggered());
}
use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.
the class UseChecksumFromTransferDecoratorForTrackingRecordTest method run.
@BMRules(rules = { @BMRule(name = "setup_metadata_countdown", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "<init>", targetLocation = "ENTRY", action = "System.out.println(\"SETUP COUNTDOWN\"); createCountDown(\"COUNTDOWN\", 1);"), @BMRule(name = "prevent_successive_metadata_additions", targetClass = "^org.commonjava.indy.content.ContentDigester", isInterface = true, targetMethod = "addMetadata", targetLocation = "ENTRY", binding = "path:String = $1.getPath();", condition = "path.endsWith(\"path/to/foo.class\") && countDown(\"COUNTDOWN\")", action = "System.out.println(\"RETURN NULL\"); return null;") })
@Test
public void run() throws Exception {
final String trackingId = newName();
final String repoId = "repo";
final String path = "/path/to/foo.class";
final InputStream stream = new ByteArrayInputStream("This is a test with the same content each time.".getBytes());
server.expect(server.formatUrl(repoId, path), 200, stream);
RemoteRepository rr = new RemoteRepository(repoId, server.formatUrl(repoId));
rr = client.stores().create(rr, "adding test remote", RemoteRepository.class);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final InputStream in = client.module(IndyFoloContentClientModule.class).get(trackingId, remote, repoId, path);
IOUtils.copy(in, baos);
in.close();
final byte[] bytes = baos.toByteArray();
final String md5 = md5Hex(bytes);
final String sha256 = sha256Hex(bytes);
assertThat(md5, equalTo(DigestUtils.md5Hex(bytes)));
assertThat(sha256, equalTo(DigestUtils.sha256Hex(bytes)));
waitForEventPropagation();
assertThat(client.module(IndyFoloAdminClientModule.class).sealTrackingRecord(trackingId), equalTo(true));
final TrackedContentDTO report = client.module(IndyFoloAdminClientModule.class).getTrackingReport(trackingId);
assertThat(report, notNullValue());
final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
assertThat(downloads, notNullValue());
assertThat(downloads.size(), equalTo(1));
final TrackedContentEntryDTO entry = downloads.iterator().next();
System.out.println(entry);
assertThat(entry, notNullValue());
assertThat(entry.getStoreKey(), equalTo(new StoreKey(remote, repoId)));
assertThat(entry.getPath(), equalTo(path));
assertThat(entry.getLocalUrl(), equalTo(client.content().contentUrl(remote, repoId, path)));
assertThat(entry.getOriginUrl(), equalTo(server.formatUrl(repoId, path)));
assertThat(entry.getMd5(), equalTo(md5));
assertThat(entry.getSha256(), equalTo(sha256));
}
use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.
the class ConcurrencyTest method deadlockOnGroupContains.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getGroupsContaining call", targetClass = "MemoryStoreDataManager", targetMethod = "getGroupsContaining", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void deadlockOnGroupContains() throws IndyDataException, InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(2);
ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
AtomicInteger count = new AtomicInteger(0);
RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
TestUpdatingEventDispatcher dispatcher = new TestUpdatingEventDispatcher(repo, completionService, count);
MemoryStoreDataManager dataManager = new MemoryStoreDataManager(dispatcher, new DefaultIndyConfiguration());
dispatcher.setDataManager(dataManager);
ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test init");
dataManager.storeArtifactStore(repo, summary, false, false, new EventMetadata());
for (int i = 0; i < 2; i++) {
Group group = new Group(MAVEN_PKG_KEY, "group" + i);
if (i % 2 == 0) {
group.addConstituent(repo);
}
dataManager.storeArtifactStore(group, summary, false, false, new EventMetadata());
}
for (int i = 0; i < count.get(); i++) {
Future<String> future = completionService.take();
assertThat(future.get(), nullValue());
}
}
use of org.jboss.byteman.contrib.bmunit.BMRules in project indy by Commonjava.
the class GitManagerConcurrentTest method concurrentAddToRepo.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "GitManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "addAndCommitPaths call", targetClass = "GitManager", targetMethod = "addAndCommitPaths(ChangeSummary,Collection)", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void concurrentAddToRepo() throws Exception {
final int threshold = 2;
final Executor pool = Executors.newFixedThreadPool(threshold);
CountDownLatch latch = new CountDownLatch(threshold);
for (int i = 0; i < threshold; i++) {
final int j = i;
pool.execute(() -> {
try {
final File f = new File(cloneDir, String.format("test%s.txt", j));
FileUtils.write(f, String.format("This is a test %s", j));
final String user = "test" + j;
final String log = "test commit " + j;
git.addAndCommitFiles(new ChangeSummary(user, log), f);
} catch (Exception e) {
e.printStackTrace();
failed = true;
} finally {
latch.countDown();
}
});
}
latch.await();
if (failed) {
fail();
}
}
Aggregations