Repository: cassandra
Updated Branches:
  refs/heads/trunk add855ae1 -> cc26c8304


Remove deprecated repair API

patch by yukim; reviewed by Paulo Motta for CASSANDRA-11530


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/cc26c830
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/cc26c830
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/cc26c830

Branch: refs/heads/trunk
Commit: cc26c8304b4d4312213a0175dcd5f1531e7934ad
Parents: add855a
Author: Yuki Morishita <yu...@apache.org>
Authored: Fri Mar 17 15:04:28 2017 +0900
Committer: Yuki Morishita <yu...@apache.org>
Committed: Mon Apr 3 10:44:25 2017 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 NEWS.txt                                        |   1 +
 .../apache/cassandra/repair/RepairRunnable.java |  10 -
 .../cassandra/service/ActiveRepairService.java  |  11 --
 .../cassandra/service/StorageService.java       | 192 +------------------
 .../cassandra/service/StorageServiceMBean.java  |  49 -----
 .../progress/jmx/LegacyJMXProgressSupport.java  | 107 -----------
 .../jmx/LegacyJMXProgressSupportTest.java       | 118 ------------
 8 files changed, 8 insertions(+), 481 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index f64e6a0..adb4caf 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 4.0
+ * Remove deprecated repair JMX APIs (CASSANDRA-11530)
  * Fix version check to enable streaming keep-alive (CASSANDRA-12929)
  * Make it possible to monitor an ideal consistency level separate from actual 
consistency level (CASSANDRA-13289)
  * Outbound TCP connections ignore internode authenticator (CASSANDRA-13324)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/NEWS.txt
----------------------------------------------------------------------
diff --git a/NEWS.txt b/NEWS.txt
index 29e7a5b..1ec4637 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -48,6 +48,7 @@ Upgrading
       repaired. For incremental repairs, anticompaction is run at the beginning
       of the repair, instead of at the end.
     - Config option index_interval has been removed (it was deprecated since 
2.0)
+    - Deprecated repair JMX APIs are removed.
 
 3.11.0
 ======

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/src/java/org/apache/cassandra/repair/RepairRunnable.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/repair/RepairRunnable.java 
b/src/java/org/apache/cassandra/repair/RepairRunnable.java
index 7d9c1d6..986bd7c 100644
--- a/src/java/org/apache/cassandra/repair/RepairRunnable.java
+++ b/src/java/org/apache/cassandra/repair/RepairRunnable.java
@@ -360,11 +360,6 @@ public class RepairRunnable extends WrappedRunnable 
implements ProgressEventNoti
 
         public void onSuccess(RepairSessionResult result)
         {
-            /**
-             * If the success message below is modified, it must also be 
updated on
-             * {@link 
org.apache.cassandra.utils.progress.jmx.LegacyJMXProgressSupport}
-             * for backward-compatibility support.
-             */
             String message = String.format("Repair session %s for range %s 
finished", session.getId(),
                                            session.getRanges().toString());
             logger.info(message);
@@ -376,11 +371,6 @@ public class RepairRunnable extends WrappedRunnable 
implements ProgressEventNoti
 
         public void onFailure(Throwable t)
         {
-            /**
-             * If the failure message below is modified, it must also be 
updated on
-             * {@link 
org.apache.cassandra.utils.progress.jmx.LegacyJMXProgressSupport}
-             * for backward-compatibility support.
-             */
             String message = String.format("Repair session %s for range %s 
failed with error %s",
                                            session.getId(), 
session.getRanges().toString(), t.getMessage());
             logger.error(message, t);

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/src/java/org/apache/cassandra/service/ActiveRepairService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/ActiveRepairService.java 
b/src/java/org/apache/cassandra/service/ActiveRepairService.java
index 5e33913..381af48 100644
--- a/src/java/org/apache/cassandra/service/ActiveRepairService.java
+++ b/src/java/org/apache/cassandra/service/ActiveRepairService.java
@@ -89,17 +89,6 @@ import org.apache.cassandra.utils.UUIDGen;
  */
 public class ActiveRepairService implements IEndpointStateChangeSubscriber, 
IFailureDetectionEventListener, ActiveRepairServiceMBean
 {
-    /**
-     * @deprecated this statuses are from the previous JMX notification 
service,
-     * which will be deprecated on 4.0. For statuses of the new notification
-     * service, see {@link 
org.apache.cassandra.streaming.StreamEvent.ProgressEvent}
-     */
-    @Deprecated
-    public static enum Status
-    {
-        STARTED, SESSION_SUCCESS, SESSION_FAILED, FINISHED
-    }
-
     public static class ConsistentSessions
     {
         public final LocalSessions local = new LocalSessions();

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageService.java 
b/src/java/org/apache/cassandra/service/StorageService.java
index 9e6eb1d..19e7f5b 100644
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@ -100,7 +100,6 @@ import org.apache.cassandra.utils.*;
 import org.apache.cassandra.utils.progress.ProgressEvent;
 import org.apache.cassandra.utils.progress.ProgressEventType;
 import org.apache.cassandra.utils.progress.jmx.JMXProgressSupport;
-import org.apache.cassandra.utils.progress.jmx.LegacyJMXProgressSupport;
 
 import static java.util.Arrays.asList;
 import static java.util.stream.Collectors.toList;
@@ -121,13 +120,6 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
 
     private final JMXProgressSupport progressSupport = new 
JMXProgressSupport(this);
 
-    /**
-     * @deprecated backward support to previous notification interface
-     * Will be removed on 4.0
-     */
-    @Deprecated
-    private final LegacyJMXProgressSupport legacyProgressSupport;
-
     private static final AtomicInteger threadCounter = new AtomicInteger(1);
 
     private static int getRingDelay()
@@ -262,8 +254,6 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
             throw new RuntimeException(e);
         }
 
-        legacyProgressSupport = new LegacyJMXProgressSupport(this, 
jmxObjectName);
-
         ReadCommandVerbHandler readHandler = new ReadCommandVerbHandler();
 
         /* register the verb handlers */
@@ -3272,170 +3262,12 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
                 option.getRanges().addAll(getLocalRanges(keyspace));
             }
         }
-        return forceRepairAsync(keyspace, option, false);
-    }
-
-    @Deprecated
-    public int forceRepairAsync(String keyspace,
-                                boolean isSequential,
-                                Collection<String> dataCenters,
-                                Collection<String> hosts,
-                                boolean primaryRange,
-                                boolean fullRepair,
-                                String... tableNames)
-    {
-        return forceRepairAsync(keyspace, isSequential ? 
RepairParallelism.SEQUENTIAL.ordinal() : RepairParallelism.PARALLEL.ordinal(), 
dataCenters, hosts, primaryRange, fullRepair, tableNames);
-    }
-
-    @Deprecated
-    public int forceRepairAsync(String keyspace,
-                                int parallelismDegree,
-                                Collection<String> dataCenters,
-                                Collection<String> hosts,
-                                boolean primaryRange,
-                                boolean fullRepair,
-                                String... tableNames)
-    {
-        if (parallelismDegree < 0 || parallelismDegree > 
RepairParallelism.values().length - 1)
-        {
-            throw new IllegalArgumentException("Invalid parallelism degree 
specified: " + parallelismDegree);
-        }
-        RepairParallelism parallelism = 
RepairParallelism.values()[parallelismDegree];
-        if (FBUtilities.isWindows && parallelism != RepairParallelism.PARALLEL)
-        {
-            logger.warn("Snapshot-based repair is not yet supported on 
Windows.  Reverting to parallel repair.");
-            parallelism = RepairParallelism.PARALLEL;
-        }
-
-        RepairOption options = new RepairOption(parallelism, primaryRange, 
!fullRepair, false, 1, Collections.<Range<Token>>emptyList(), false, false);
-        if (dataCenters != null)
-        {
-            options.getDataCenters().addAll(dataCenters);
-        }
-        if (hosts != null)
-        {
-            options.getHosts().addAll(hosts);
-        }
-        if (primaryRange)
-        {
-            // when repairing only primary range, neither dataCenters nor 
hosts can be set
-            if (options.getDataCenters().isEmpty() && 
options.getHosts().isEmpty())
-                options.getRanges().addAll(getPrimaryRanges(keyspace));
-                // except dataCenters only contain local DC (i.e. -local)
-            else if (options.getDataCenters().size() == 1 && 
options.getDataCenters().contains(DatabaseDescriptor.getLocalDataCenter()))
-                options.getRanges().addAll(getPrimaryRangesWithinDC(keyspace));
-            else
-                throw new IllegalArgumentException("You need to run primary 
range repair on all nodes in the cluster.");
-        }
-        else
-        {
-            options.getRanges().addAll(getLocalRanges(keyspace));
-        }
-        if (tableNames != null)
-        {
-            for (String table : tableNames)
-            {
-                options.getColumnFamilies().add(table);
-            }
-        }
-        return forceRepairAsync(keyspace, options, true);
-    }
-
-    @Deprecated
-    public int forceRepairAsync(String keyspace,
-                                boolean isSequential,
-                                boolean isLocal,
-                                boolean primaryRange,
-                                boolean fullRepair,
-                                String... tableNames)
-    {
-        Set<String> dataCenters = null;
-        if (isLocal)
-        {
-            dataCenters = 
Sets.newHashSet(DatabaseDescriptor.getLocalDataCenter());
-        }
-        return forceRepairAsync(keyspace, isSequential, dataCenters, null, 
primaryRange, fullRepair, tableNames);
-    }
-
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken,
-                                     String endToken,
-                                     String keyspaceName,
-                                     boolean isSequential,
-                                     Collection<String> dataCenters,
-                                     Collection<String> hosts,
-                                     boolean fullRepair,
-                                     String... tableNames)
-    {
-        return forceRepairRangeAsync(beginToken, endToken, keyspaceName,
-                                     isSequential ? 
RepairParallelism.SEQUENTIAL.ordinal() : RepairParallelism.PARALLEL.ordinal(),
-                                     dataCenters, hosts, fullRepair, 
tableNames);
-    }
-
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken,
-                                     String endToken,
-                                     String keyspaceName,
-                                     int parallelismDegree,
-                                     Collection<String> dataCenters,
-                                     Collection<String> hosts,
-                                     boolean fullRepair,
-                                     String... tableNames)
-    {
-        if (parallelismDegree < 0 || parallelismDegree > 
RepairParallelism.values().length - 1)
-        {
-            throw new IllegalArgumentException("Invalid parallelism degree 
specified: " + parallelismDegree);
-        }
-        RepairParallelism parallelism = 
RepairParallelism.values()[parallelismDegree];
-        if (FBUtilities.isWindows && parallelism != RepairParallelism.PARALLEL)
-        {
-            logger.warn("Snapshot-based repair is not yet supported on 
Windows.  Reverting to parallel repair.");
-            parallelism = RepairParallelism.PARALLEL;
-        }
-
-        if (!fullRepair)
-            logger.warn("Incremental repair can't be requested with subrange 
repair " +
-                        "because each subrange repair would generate an 
anti-compacted table. " +
-                        "The repair will occur but without anti-compaction.");
-        Collection<Range<Token>> repairingRange = 
createRepairRangeFrom(beginToken, endToken);
-
-        RepairOption options = new RepairOption(parallelism, false, 
!fullRepair, false, 1, repairingRange, true, false);
-        if (dataCenters != null)
-        {
-            options.getDataCenters().addAll(dataCenters);
-        }
-        if (hosts != null)
-        {
-            options.getHosts().addAll(hosts);
-        }
-        if (tableNames != null)
-        {
-            for (String table : tableNames)
-            {
-                options.getColumnFamilies().add(table);
-            }
-        }
-
-        logger.info("starting user-requested repair of range {} for keyspace 
{} and column families {}",
-                    repairingRange, keyspaceName, tableNames);
-        return forceRepairAsync(keyspaceName, options, true);
-    }
+        if (option.getRanges().isEmpty() || 
Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor() < 2)
+            return 0;
 
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken,
-                                     String endToken,
-                                     String keyspaceName,
-                                     boolean isSequential,
-                                     boolean isLocal,
-                                     boolean fullRepair,
-                                     String... tableNames)
-    {
-        Set<String> dataCenters = null;
-        if (isLocal)
-        {
-            dataCenters = 
Sets.newHashSet(DatabaseDescriptor.getLocalDataCenter());
-        }
-        return forceRepairRangeAsync(beginToken, endToken, keyspaceName, 
isSequential, dataCenters, null, fullRepair, tableNames);
+        int cmd = nextRepairCommand.incrementAndGet();
+        NamedThreadFactory.createThread(createRepairTask(cmd, keyspace, 
option), "Repair-Task-" + threadCounter.incrementAndGet()).start();
+        return cmd;
     }
 
     /**
@@ -3481,17 +3313,7 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
         return tokenMetadata.partitioner.getTokenFactory();
     }
 
-    public int forceRepairAsync(String keyspace, RepairOption options, boolean 
legacy)
-    {
-        if (options.getRanges().isEmpty() || 
Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor() < 2)
-            return 0;
-
-        int cmd = nextRepairCommand.incrementAndGet();
-        NamedThreadFactory.createThread(createRepairTask(cmd, keyspace, 
options, legacy), "Repair-Task-" + threadCounter.incrementAndGet()).start();
-        return cmd;
-    }
-
-    private FutureTask<Object> createRepairTask(final int cmd, final String 
keyspace, final RepairOption options, boolean legacy)
+    private FutureTask<Object> createRepairTask(final int cmd, final String 
keyspace, final RepairOption options)
     {
         if (!options.getDataCenters().isEmpty() && 
!options.getDataCenters().contains(DatabaseDescriptor.getLocalDataCenter()))
         {
@@ -3500,8 +3322,6 @@ public class StorageService extends 
NotificationBroadcasterSupport implements IE
 
         RepairRunnable task = new RepairRunnable(this, cmd, options, keyspace);
         task.addProgressListener(progressSupport);
-        if (legacy)
-            task.addProgressListener(legacyProgressSupport);
         return new FutureTask<>(task, null);
     }
 

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/src/java/org/apache/cassandra/service/StorageServiceMBean.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/service/StorageServiceMBean.java 
b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
index 5325e86..348610a 100644
--- a/src/java/org/apache/cassandra/service/StorageServiceMBean.java
+++ b/src/java/org/apache/cassandra/service/StorageServiceMBean.java
@@ -322,55 +322,6 @@ public interface StorageServiceMBean extends 
NotificationEmitter
      */
     public int repairAsync(String keyspace, Map<String, String> options);
 
-    /**
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     */
-    @Deprecated
-    public int forceRepairAsync(String keyspace, boolean isSequential, 
Collection<String> dataCenters, Collection<String> hosts,  boolean 
primaryRange, boolean fullRepair, String... tableNames) throws IOException;
-
-    /**
-     * Invoke repair asynchronously.
-     * You can track repair progress by subscribing JMX notification sent from 
this StorageServiceMBean.
-     * Notification format is:
-     *   type: "repair"
-     *   userObject: int array of length 2, [0]=command number, [1]=ordinal of 
ActiveRepairService.Status
-     *
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     *
-     * @param parallelismDegree 0: sequential, 1: parallel, 2: DC parallel
-     * @return Repair command number, or 0 if nothing to repair
-     */
-    @Deprecated
-    public int forceRepairAsync(String keyspace, int parallelismDegree, 
Collection<String> dataCenters, Collection<String> hosts, boolean primaryRange, 
boolean fullRepair, String... tableNames);
-
-    /**
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     */
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken, String endToken, 
String keyspaceName, boolean isSequential, Collection<String> dataCenters, 
Collection<String> hosts, boolean fullRepair, String... tableNames) throws 
IOException;
-
-    /**
-     * Same as forceRepairAsync, but handles a specified range
-     *
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     *
-     * @param parallelismDegree 0: sequential, 1: parallel, 2: DC parallel
-     */
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken, String endToken, 
String keyspaceName, int parallelismDegree, Collection<String> dataCenters, 
Collection<String> hosts, boolean fullRepair, String... tableNames);
-
-    /**
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     */
-    @Deprecated
-    public int forceRepairAsync(String keyspace, boolean isSequential, boolean 
isLocal, boolean primaryRange, boolean fullRepair, String... tableNames);
-
-    /**
-     * @deprecated use {@link #repairAsync(String keyspace, Map options)} 
instead.
-     */
-    @Deprecated
-    public int forceRepairRangeAsync(String beginToken, String endToken, 
String keyspaceName, boolean isSequential, boolean isLocal, boolean fullRepair, 
String... tableNames);
-
     public void forceTerminateAllRepairSessions();
 
     /**

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/src/java/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupport.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupport.java
 
b/src/java/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupport.java
deleted file mode 100644
index a33fe7d..0000000
--- 
a/src/java/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupport.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.utils.progress.jmx;
-
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.regex.Pattern;
-import javax.management.Notification;
-import javax.management.NotificationBroadcasterSupport;
-import javax.management.ObjectName;
-
-import org.apache.cassandra.utils.progress.ProgressEvent;
-import org.apache.cassandra.utils.progress.ProgressListener;
-
-import static org.apache.cassandra.service.ActiveRepairService.Status;
-
-/**
- * ProgressListener that translates ProgressEvent to legacy JMX Notification 
message (backward compatibility support)
- */
-public class LegacyJMXProgressSupport implements ProgressListener
-{
-    protected static final Pattern SESSION_FAILED_MATCHER = 
Pattern.compile("Repair session .* for range .* failed with error .*");
-    protected static final Pattern SESSION_SUCCESS_MATCHER = 
Pattern.compile("Repair session .* for range .* finished");
-
-    private final AtomicLong notificationSerialNumber = new AtomicLong();
-    private final ObjectName jmxObjectName;
-
-    private final NotificationBroadcasterSupport broadcaster;
-
-    public LegacyJMXProgressSupport(NotificationBroadcasterSupport broadcaster,
-                                    ObjectName jmxObjectName)
-    {
-        this.broadcaster = broadcaster;
-        this.jmxObjectName = jmxObjectName;
-    }
-
-    @Override
-    public void progress(String tag, ProgressEvent event)
-    {
-        if (tag.startsWith("repair:"))
-        {
-            Optional<int[]> legacyUserData = getLegacyUserdata(tag, event);
-            if (legacyUserData.isPresent())
-            {
-                Notification jmxNotification = new Notification("repair", 
jmxObjectName, notificationSerialNumber.incrementAndGet(), event.getMessage());
-                jmxNotification.setUserData(legacyUserData.get());
-                broadcaster.sendNotification(jmxNotification);
-            }
-        }
-    }
-
-    protected static Optional<int[]> getLegacyUserdata(String tag, 
ProgressEvent event)
-    {
-        Optional<Status> status = getStatus(event);
-        if (status.isPresent())
-        {
-            int[] result = new int[2];
-            result[0] = getCmd(tag);
-            result[1] = status.get().ordinal();
-            return Optional.of(result);
-        }
-        return Optional.empty();
-    }
-
-    protected static Optional<Status> getStatus(ProgressEvent event)
-    {
-        switch (event.getType())
-        {
-            case START:
-                return Optional.of(Status.STARTED);
-            case COMPLETE:
-                return Optional.of(Status.FINISHED);
-            case PROGRESS:
-                if 
(SESSION_FAILED_MATCHER.matcher(event.getMessage()).matches())
-                {
-                    return Optional.of(Status.SESSION_FAILED);
-                }
-                else if 
(SESSION_SUCCESS_MATCHER.matcher(event.getMessage()).matches())
-                {
-                    return Optional.of(Status.SESSION_SUCCESS);
-                }
-        }
-
-        return Optional.empty();
-    }
-
-    protected static int getCmd(String tag)
-    {
-        return Integer.parseInt(tag.split(":")[1]);
-    }
-}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc26c830/test/unit/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupportTest.java
----------------------------------------------------------------------
diff --git 
a/test/unit/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupportTest.java
 
b/test/unit/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupportTest.java
deleted file mode 100644
index 70fb5cc..0000000
--- 
a/test/unit/org/apache/cassandra/utils/progress/jmx/LegacyJMXProgressSupportTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.cassandra.utils.progress.jmx;
-
-import java.util.Optional;
-import java.util.UUID;
-
-import org.junit.Test;
-
-import org.apache.cassandra.dht.Murmur3Partitioner;
-import org.apache.cassandra.dht.Range;
-import org.apache.cassandra.dht.Token;
-import org.apache.cassandra.service.ActiveRepairService;
-import org.apache.cassandra.utils.progress.ProgressEvent;
-import org.apache.cassandra.utils.progress.ProgressEventType;
-
-import static org.junit.Assert.*;
-
-
-public class LegacyJMXProgressSupportTest
-{
-
-    @Test
-    public void testSessionSuccess()
-    {
-        int cmd = 321;
-        String message = String.format("Repair session %s for range %s 
finished", UUID.randomUUID(),
-                                       new Range<Token>(new 
Murmur3Partitioner.LongToken(3), new Murmur3Partitioner.LongToken(4)));
-        Optional<int[]> result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                            new 
ProgressEvent(ProgressEventType.PROGRESS, 2, 10, message));
-        assertTrue(result.isPresent());
-        assertArrayEquals(new int[]{ cmd, 
ActiveRepairService.Status.SESSION_SUCCESS.ordinal() }, result.get());
-    }
-
-    @Test
-    public void testSessionFailed()
-    {
-        int cmd = 321;
-        String message = String.format("Repair session %s for range %s failed 
with error %s", UUID.randomUUID(),
-                                       new Range<Token>(new 
Murmur3Partitioner.LongToken(3), new 
Murmur3Partitioner.LongToken(4)).toString(),
-                                       new RuntimeException("error"));
-        Optional<int[]> result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                                            
new ProgressEvent(ProgressEventType.PROGRESS, 2, 10, message));
-        assertTrue(result.isPresent());
-        assertArrayEquals(new int[]{ cmd, 
ActiveRepairService.Status.SESSION_FAILED.ordinal() }, result.get());
-    }
-
-    @Test
-    public void testStarted()
-    {
-        int cmd = 321;
-        Optional<int[]> result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                                            
new ProgressEvent(ProgressEventType.START,
-                                                                               
               0, 100, "bla"));
-        assertTrue(result.isPresent());
-        assertArrayEquals(new int[]{ cmd, 
ActiveRepairService.Status.STARTED.ordinal() }, result.get());
-    }
-
-    @Test
-    public void testFinished()
-    {
-        int cmd = 321;
-        Optional<int[]> result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                                         new 
ProgressEvent(ProgressEventType.COMPLETE,
-                                                                               
            2, 10, "bla"));
-        assertTrue(result.isPresent());
-        assertArrayEquals(new int[]{ cmd, 
ActiveRepairService.Status.FINISHED.ordinal() }, result.get());
-    }
-
-    /*
-    States not mapped to the legacy notification
-     */
-    @Test
-    public void testNone()
-    {
-        int cmd = 33;
-        Optional<int[]> result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                                         new 
ProgressEvent(ProgressEventType.ERROR, 2, 10, "bla"));
-        assertFalse(result.isPresent());
-
-        cmd = 33;
-        result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                                         new 
ProgressEvent(ProgressEventType.SUCCESS, 2, 10, "bla"));
-        assertFalse(result.isPresent());
-
-        cmd = 43;
-        result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                            new 
ProgressEvent(ProgressEventType.PROGRESS, 2, 10, "bla"));
-        assertFalse(result.isPresent());
-
-        cmd = 1;
-        result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                            new 
ProgressEvent(ProgressEventType.ABORT, 2, 10, "bla"));
-        assertFalse(result.isPresent());
-
-        cmd = 9;
-        result = 
LegacyJMXProgressSupport.getLegacyUserdata(String.format("repair:%d", cmd),
-                                                            new 
ProgressEvent(ProgressEventType.NOTIFICATION, 2, 10, "bla"));
-        assertFalse(result.isPresent());
-    }
-
-}

Reply via email to