Search in sources :

Example 1 with IMessageFilters

use of org.apache.cassandra.distributed.api.IMessageFilters in project cassandra by apache.

the class MessageFiltersTest method executeWithWriteFailure.

public Object[][] executeWithWriteFailure(Cluster cluster, String statement, ConsistencyLevel cl, int coordinator, Object... bindings) {
    IMessageFilters filters = cluster.filters();
    // Drop exactly one coordinated message
    filters.verbs(Verb.MUTATION_REQ.id).from(coordinator).messagesMatching(new IMessageFilters.Matcher() {

        private final AtomicBoolean issued = new AtomicBoolean();

        public boolean matches(int from, int to, IMessage message) {
            if (from != coordinator || message.verb() != Verb.MUTATION_REQ.id)
                return false;
            return !issued.getAndSet(true);
        }
    }).drop().on();
    Object[][] res = cluster.coordinator(coordinator).execute(statement, cl, bindings);
    filters.reset();
    return res;
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMessageFilters(org.apache.cassandra.distributed.api.IMessageFilters) IMessage(org.apache.cassandra.distributed.api.IMessage)

Example 2 with IMessageFilters

use of org.apache.cassandra.distributed.api.IMessageFilters in project cassandra by apache.

the class InJvmSutBase method executeWithWriteFailure.

// TODO: Ideally, we need to be able to induce a failure of a single specific message
public Object[][] executeWithWriteFailure(String statement, ConsistencyLevel cl, Object... bindings) {
    if (isShutdown.get())
        throw new RuntimeException("Instance is shut down");
    try {
        int coordinator = (int) (cnt.getAndIncrement() % cluster.size() + 1);
        IMessageFilters filters = cluster.filters();
        // Drop exactly one coordinated message
        int MUTATION_REQ = 0;
        // TODO: make dropping deterministic
        filters.verbs(MUTATION_REQ).from(coordinator).messagesMatching(new IMessageFilters.Matcher() {

            private final AtomicBoolean issued = new AtomicBoolean();

            public boolean matches(int from, int to, IMessage message) {
                if (from != coordinator || message.verb() != MUTATION_REQ)
                    return false;
                return !issued.getAndSet(true);
            }
        }).drop().on();
        Object[][] res = cluster.coordinator(coordinator).execute(statement, toApiCl(cl), bindings);
        filters.reset();
        return res;
    } catch (Throwable t) {
        logger.error(String.format("Caught error while trying execute statement %s", statement), t);
        throw t;
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMessageFilters(org.apache.cassandra.distributed.api.IMessageFilters) IMessage(org.apache.cassandra.distributed.api.IMessage)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IMessage (org.apache.cassandra.distributed.api.IMessage)2 IMessageFilters (org.apache.cassandra.distributed.api.IMessageFilters)2