Class CassandraCluster<I extends org.apache.cassandra.distributed.api.IInstance>

  • Type Parameters:
    I - the type of the cluster instance
    All Implemented Interfaces:
    java.lang.AutoCloseable, java.lang.Iterable<I>, org.apache.cassandra.distributed.api.ICluster<I>, IClusterExtension<I>

    public class CassandraCluster<I extends org.apache.cassandra.distributed.api.IInstance>
    extends java.lang.Object
    implements IClusterExtension<I>
    Implements the IClusterExtension interface, delegating the functionality to the delegate. This class is meant to be loaded in a different classloader.
    • Field Summary

      • Fields inherited from interface org.apache.cassandra.distributed.api.ICluster

        PROPERTY_PREFIX
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      I addInstance​(java.lang.String dc, java.lang.String rack, java.util.function.Consumer<org.apache.cassandra.distributed.api.IInstanceConfig> fn)
      Create a new instance and add it to the cluster, without starting it.
      void awaitGossipStatus​(org.apache.cassandra.distributed.api.IInstance instance, org.apache.cassandra.distributed.api.IInstance expectedInGossip, java.lang.String targetStatus)
      Waits for the target instance to have the desired status.
      void awaitRingState​(org.apache.cassandra.distributed.api.IInstance instance, org.apache.cassandra.distributed.api.IInstance expectedInRing, java.lang.String state)
      Waits for the ring to have the target instance with the provided state.
      void awaitRingStatus​(org.apache.cassandra.distributed.api.IInstance instance, org.apache.cassandra.distributed.api.IInstance expectedInRing, java.lang.String status)
      Wait for the ring to have the target instance with the provided status.
      I bootstrap​(org.apache.cassandra.distributed.api.IInstanceConfig iInstanceConfig)  
      void checkAndResetUncaughtExceptions()  
      void close()  
      org.apache.cassandra.distributed.api.ICoordinator coordinator​(int i)  
      org.apache.cassandra.distributed.api.ICluster<I> delegate()  
      void deliverMessage​(java.net.InetSocketAddress to, org.apache.cassandra.distributed.api.IMessage msg)  
      org.apache.cassandra.distributed.api.IMessageFilters filters()  
      void forEach​(java.util.function.Consumer<? super I> action)  
      I get​(int i)  
      I get​(java.net.InetSocketAddress inetSocketAddress)  
      I getFirstRunningInstance()  
      org.apache.cassandra.distributed.impl.AbstractCluster<I> initializeCluster​(java.lang.String versionString, ClusterBuilderConfiguration configuration)  
      java.util.Iterator<I> iterator()  
      org.apache.cassandra.distributed.api.IInstanceConfig newInstanceConfig()  
      void schemaChange​(java.lang.String s)  
      void schemaChange​(java.lang.String s, int i)  
      void schemaChangeIgnoringStoppedInstances​(java.lang.String query)
      Change the schema of the cluster, tolerating stopped nodes.
      void setMessageSink​(org.apache.cassandra.distributed.api.IMessageSink messageSink)  
      void setUncaughtExceptionsFilter​(java.util.function.BiPredicate<java.lang.Integer,​java.lang.Throwable> ignoreThrowable)  
      void setUncaughtExceptionsFilter​(java.util.function.Predicate<java.lang.Throwable> ignoreThrowable)  
      int size()  
      java.util.Spliterator<I> spliterator()  
      void startup()  
      void stopUnchecked​(org.apache.cassandra.distributed.api.IInstance instance)
      Stop an instance in a blocking manner.
      java.util.stream.Stream<I> stream()  
      java.util.stream.Stream<I> stream​(java.lang.String s)  
      java.util.stream.Stream<I> stream​(java.lang.String s, java.lang.String s1)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CassandraCluster

        public CassandraCluster​(java.lang.String versionString,
                                ClusterBuilderConfiguration configuration)
                         throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • initializeCluster

        public org.apache.cassandra.distributed.impl.AbstractCluster<I> initializeCluster​(java.lang.String versionString,
                                                                                          ClusterBuilderConfiguration configuration)
                                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • schemaChangeIgnoringStoppedInstances

        public void schemaChangeIgnoringStoppedInstances​(java.lang.String query)
        Description copied from interface: IClusterExtension
        Change the schema of the cluster, tolerating stopped nodes. N.B. the schema will not automatically be updated when stopped nodes are restarted, individual tests need to re-synchronize somehow (by gossip or some other mechanism).
        Specified by:
        schemaChangeIgnoringStoppedInstances in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        query - Schema altering statement
      • addInstance

        public I addInstance​(java.lang.String dc,
                             java.lang.String rack,
                             java.util.function.Consumer<org.apache.cassandra.distributed.api.IInstanceConfig> fn)
        Description copied from interface: IClusterExtension
        Create a new instance and add it to the cluster, without starting it.
        Specified by:
        addInstance in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        dc - the instance should be in
        rack - the instance should be in
        fn - function to add to the config before starting
        Returns:
        the instance added
      • getFirstRunningInstance

        public I getFirstRunningInstance()
        Specified by:
        getFirstRunningInstance in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Returns:
        the first instance with running state
      • newInstanceConfig

        public org.apache.cassandra.distributed.api.IInstanceConfig newInstanceConfig()
        Specified by:
        newInstanceConfig in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Returns:
        a newly created instance configuration
      • delegate

        public org.apache.cassandra.distributed.api.ICluster<I> delegate()
        Specified by:
        delegate in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Returns:
        a reference to the delegated ICluster instance
      • awaitRingState

        public void awaitRingState​(org.apache.cassandra.distributed.api.IInstance instance,
                                   org.apache.cassandra.distributed.api.IInstance expectedInRing,
                                   java.lang.String state)
        Description copied from interface: IClusterExtension
        Waits for the ring to have the target instance with the provided state.
        Specified by:
        awaitRingState in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        instance - instance to check on
        expectedInRing - to look for
        state - expected
      • awaitRingStatus

        public void awaitRingStatus​(org.apache.cassandra.distributed.api.IInstance instance,
                                    org.apache.cassandra.distributed.api.IInstance expectedInRing,
                                    java.lang.String status)
        Description copied from interface: IClusterExtension
        Wait for the ring to have the target instance with the provided status.
        Specified by:
        awaitRingStatus in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        instance - instance to check on
        expectedInRing - to look for
        status - expected
      • awaitGossipStatus

        public void awaitGossipStatus​(org.apache.cassandra.distributed.api.IInstance instance,
                                      org.apache.cassandra.distributed.api.IInstance expectedInGossip,
                                      java.lang.String targetStatus)
        Description copied from interface: IClusterExtension
        Waits for the target instance to have the desired status. Target status is checked via string contains so works with 'NORMAL' but also can check tokens or full state.
        Specified by:
        awaitGossipStatus in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        instance - instance to check on
        expectedInGossip - instance to wait for
        targetStatus - for the instance
      • stopUnchecked

        public void stopUnchecked​(org.apache.cassandra.distributed.api.IInstance instance)
        Description copied from interface: IClusterExtension
        Stop an instance in a blocking manner.

        The main difference between this and IInstance.shutdown() is that the wait on the future will catch the exceptions and throw as runtime.

        Specified by:
        stopUnchecked in interface IClusterExtension<I extends org.apache.cassandra.distributed.api.IInstance>
        Parameters:
        instance - instance to stop
      • startup

        public void startup()
        Specified by:
        startup in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • bootstrap

        public I bootstrap​(org.apache.cassandra.distributed.api.IInstanceConfig iInstanceConfig)
        Specified by:
        bootstrap in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • get

        public I get​(int i)
        Specified by:
        get in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • get

        public I get​(java.net.InetSocketAddress inetSocketAddress)
        Specified by:
        get in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • coordinator

        public org.apache.cassandra.distributed.api.ICoordinator coordinator​(int i)
        Specified by:
        coordinator in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • schemaChange

        public void schemaChange​(java.lang.String s)
        Specified by:
        schemaChange in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • schemaChange

        public void schemaChange​(java.lang.String s,
                                 int i)
        Specified by:
        schemaChange in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • size

        public int size()
        Specified by:
        size in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • stream

        public java.util.stream.Stream<I> stream()
        Specified by:
        stream in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • stream

        public java.util.stream.Stream<I> stream​(java.lang.String s)
        Specified by:
        stream in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • stream

        public java.util.stream.Stream<I> stream​(java.lang.String s,
                                                 java.lang.String s1)
        Specified by:
        stream in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • iterator

        @NotNull
        public java.util.Iterator<I> iterator()
        Specified by:
        iterator in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
        Specified by:
        iterator in interface java.lang.Iterable<I extends org.apache.cassandra.distributed.api.IInstance>
      • filters

        public org.apache.cassandra.distributed.api.IMessageFilters filters()
        Specified by:
        filters in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • setMessageSink

        public void setMessageSink​(org.apache.cassandra.distributed.api.IMessageSink messageSink)
        Specified by:
        setMessageSink in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • deliverMessage

        public void deliverMessage​(java.net.InetSocketAddress to,
                                   org.apache.cassandra.distributed.api.IMessage msg)
        Specified by:
        deliverMessage in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • setUncaughtExceptionsFilter

        public void setUncaughtExceptionsFilter​(java.util.function.BiPredicate<java.lang.Integer,​java.lang.Throwable> ignoreThrowable)
        Specified by:
        setUncaughtExceptionsFilter in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • setUncaughtExceptionsFilter

        public void setUncaughtExceptionsFilter​(java.util.function.Predicate<java.lang.Throwable> ignoreThrowable)
        Specified by:
        setUncaughtExceptionsFilter in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • checkAndResetUncaughtExceptions

        public void checkAndResetUncaughtExceptions()
        Specified by:
        checkAndResetUncaughtExceptions in interface org.apache.cassandra.distributed.api.ICluster<I extends org.apache.cassandra.distributed.api.IInstance>
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • forEach

        public void forEach​(java.util.function.Consumer<? super I> action)
        Specified by:
        forEach in interface java.lang.Iterable<I extends org.apache.cassandra.distributed.api.IInstance>
      • spliterator

        public java.util.Spliterator<I> spliterator()
        Specified by:
        spliterator in interface java.lang.Iterable<I extends org.apache.cassandra.distributed.api.IInstance>