Search in sources :

Example 1 with StreamSession

use of org.apache.cassandra.streaming.StreamSession in project cassandra by apache.

the class StreamStateStoreTest method testUpdateAndQueryAvailableRanges.

@Test
public void testUpdateAndQueryAvailableRanges() {
    // let range (0, 100] of keyspace1 be bootstrapped.
    IPartitioner p = new Murmur3Partitioner();
    Token.TokenFactory factory = p.getTokenFactory();
    Range<Token> range = new Range<>(factory.fromString("0"), factory.fromString("100"));
    InetAddress local = FBUtilities.getBroadcastAddress();
    StreamSession session = new StreamSession(local, local, new DefaultConnectionFactory(), 0, true, false, null);
    session.addStreamRequest("keyspace1", Collections.singleton(range), Collections.singleton("cf"), 0);
    StreamStateStore store = new StreamStateStore();
    // session complete event that is not completed makes data not available for keyspace/ranges
    store.handleStreamEvent(new StreamEvent.SessionCompleteEvent(session));
    assertFalse(store.isDataAvailable("keyspace1", factory.fromString("50")));
    // successfully completed session adds available keyspace/ranges
    session.state(StreamSession.State.COMPLETE);
    store.handleStreamEvent(new StreamEvent.SessionCompleteEvent(session));
    // check if token in range (0, 100] appears available.
    assertTrue(store.isDataAvailable("keyspace1", factory.fromString("50")));
    // check if token out of range returns false
    assertFalse(store.isDataAvailable("keyspace1", factory.fromString("0")));
    assertFalse(store.isDataAvailable("keyspace1", factory.fromString("101")));
    // check if different keyspace returns false
    assertFalse(store.isDataAvailable("keyspace2", factory.fromString("50")));
    // add different range within the same keyspace
    Range<Token> range2 = new Range<>(factory.fromString("100"), factory.fromString("200"));
    session = new StreamSession(local, local, new DefaultConnectionFactory(), 0, true, false, null);
    session.addStreamRequest("keyspace1", Collections.singleton(range2), Collections.singleton("cf"), 0);
    session.state(StreamSession.State.COMPLETE);
    store.handleStreamEvent(new StreamEvent.SessionCompleteEvent(session));
    // newly added range should be available
    assertTrue(store.isDataAvailable("keyspace1", factory.fromString("101")));
    // as well as the old one
    assertTrue(store.isDataAvailable("keyspace1", factory.fromString("50")));
}
Also used : DefaultConnectionFactory(org.apache.cassandra.streaming.DefaultConnectionFactory) StreamSession(org.apache.cassandra.streaming.StreamSession) StreamEvent(org.apache.cassandra.streaming.StreamEvent) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Aggregations

InetAddress (java.net.InetAddress)1 DefaultConnectionFactory (org.apache.cassandra.streaming.DefaultConnectionFactory)1 StreamEvent (org.apache.cassandra.streaming.StreamEvent)1 StreamSession (org.apache.cassandra.streaming.StreamSession)1 Test (org.junit.Test)1