Search in sources :

Example 6 with BMScript

use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentTest method testDeleteWhenReadCompleted.

@Test
@BMScript("TryToDeleteWhileReadingCompleted.btm")
public void testDeleteWhenReadCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_delete_read.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    latchWait(latch);
    final Boolean deleted = deleteFuture.get();
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(content));
    assertThat(deleted, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 7 with BMScript

use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.

the class FastLocalCacheProviderTest method ConcurrentWriteAndReadFile.

@Test
@BMScript("ConcurrentWriteAndReadFile.btm")
public void ConcurrentWriteAndReadFile() throws Exception {
    final String content = "This is a test";
    final Location loc = new SimpleLocation("http://foo.com");
    final String fname = "/path/to/my/file.txt";
    CountDownLatch latch = new CountDownLatch(2);
    start(new ReadFileThread(loc, fname, latch));
    start(new WriteFileThread(content, loc, fname, latch));
    latchWait(latch);
    assertThat(result, equalTo(content));
}
Also used : SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) Location(org.commonjava.maven.galley.model.Location) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 8 with BMScript

use of org.jboss.byteman.contrib.bmunit.BMScript in project JGroups by belaban.

the class BecomeServerTest method testSendingOfMsgsOnUnconnectedChannel.

/**
 * When we flush the server queue and one or more of the delivered messages triggers a response (in the same thread),
 * we need to make sure the channel is connected, or else the JOIN will fail as the exception happens on the same
 * thread. Note that the suggested fix on JGRP-1522 will solve this. Issue: https://issues.jboss.org/browse/JGRP-1522
 */
@BMScript(dir = "scripts/BecomeServerTest", value = "testSendingOfMsgsOnUnconnectedChannel")
public void testSendingOfMsgsOnUnconnectedChannel() throws Exception {
    a = createChannel("A");
    a.setReceiver(new ReceiverAdapter() {

        public void receive(Message msg) {
            System.out.println("A: received message from " + msg.getSrc() + ": " + msg.getObject());
        }
    });
    a.connect("BecomeServerTest");
    new Thread("MsgSender-A") {

        public void run() {
            // will be blocked by byteman rendezvous
            sendMessage(a, "hello from A");
        }
    }.start();
    b = createChannel("B");
    b.setReceiver(new ReceiverAdapter() {

        public void receive(Message msg) {
            System.out.println("B: received message from " + msg.getSrc() + ": " + msg.getObject());
            if (msg.getSrc().equals(a.getAddress())) {
                try {
                    b.send(null, "This message would trigger an exception if the channel was not yet connected");
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        }
    });
    b.connect("BecomeServerTest");
    Util.waitUntilAllChannelsHaveSameView(20000, 1000, a, b);
    System.out.println("\nA: " + a.getView() + "\nB: " + b.getView());
}
Also used : Message(org.jgroups.Message) ReceiverAdapter(org.jgroups.ReceiverAdapter) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 9 with BMScript

use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentTest method testReadWhileDeleteCompleted.

@Test
@BMScript("TryToReadWhileDeleteCompleted.btm")
public void testReadWhileDeleteCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_read_delete_completed.txt");
    prepareBothResource(resource, content);
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    final Future<String> readingFuture = testPool.submit((Callable<String>) new ReadTask(provider, content, resource, latch));
    latchWait(latch);
    final Boolean deleted = deleteFuture.get();
    final String readingResult = readingFuture.get();
    assertThat(readingResult, equalTo(null));
    assertThat(deleted, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 10 with BMScript

use of org.jboss.byteman.contrib.bmunit.BMScript in project galley by Commonjava.

the class FastLocalCacheProviderConcurrentTest method testDeleteWhenWriteCompleted.

@Test
@BMScript("TryToDeleteWhileWritingCompleted.btm")
public void testDeleteWhenWriteCompleted() throws Exception {
    final ConcreteResource resource = createTestResource("file_delete_write_completed.txt");
    final Future<Boolean> deleteFuture = testPool.submit((Callable<Boolean>) new DeleteTask(provider, content, resource, latch));
    testPool.execute(new WriteTask(provider, content, resource, latch));
    latchWait(latch);
    final Boolean deleted = deleteFuture.get();
    assertThat(deleted, equalTo(true));
    assertThat(provider.exists(resource), equalTo(false));
}
Also used : ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

BMScript (org.jboss.byteman.contrib.bmunit.BMScript)20 Test (org.junit.Test)17 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)15 CountDownLatch (java.util.concurrent.CountDownLatch)5 Location (org.commonjava.maven.galley.model.Location)5 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)5 Message (org.jgroups.Message)2 ReceiverAdapter (org.jgroups.ReceiverAdapter)2 HashSet (java.util.HashSet)1 GMS (org.jgroups.protocols.pbcast.GMS)1