|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.cassandra.distributed.test.guardrails; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | + |
| 23 | +import org.junit.After; |
| 24 | +import org.junit.Assert; |
| 25 | +import org.junit.Before; |
| 26 | +import org.junit.Test; |
| 27 | + |
| 28 | +import org.apache.cassandra.config.CassandraRelevantProperties; |
| 29 | +import org.apache.cassandra.distributed.Cluster; |
| 30 | +import org.apache.cassandra.distributed.api.Feature; |
| 31 | +import org.apache.cassandra.distributed.api.IInvokableInstance; |
| 32 | +import org.apache.cassandra.distributed.api.TokenSupplier; |
| 33 | +import org.apache.cassandra.distributed.shared.ClusterUtils; |
| 34 | +import org.apache.cassandra.distributed.test.TestBaseImpl; |
| 35 | +import org.apache.cassandra.service.disk.usage.DiskUsageBroadcaster; |
| 36 | +import org.apache.cassandra.service.disk.usage.DiskUsageState; |
| 37 | + |
| 38 | +public class GuardrailDiskUsageNodeReplaceTest extends TestBaseImpl |
| 39 | +{ |
| 40 | + private Cluster cluster; |
| 41 | + |
| 42 | + @Before |
| 43 | + public void setupCluster() throws IOException |
| 44 | + { |
| 45 | + CassandraRelevantProperties.DISK_USAGE_MONITOR_INTERVAL_MS.setInt(100); |
| 46 | + TokenSupplier even = TokenSupplier.evenlyDistributedTokens(2); |
| 47 | + cluster = init(Cluster.build(2) |
| 48 | + .withInstanceInitializer(GuardrailDiskUsageTest.DiskStateInjection::install) |
| 49 | + .withConfig(c -> c.with(Feature.GOSSIP, Feature.NETWORK, Feature.NATIVE_PROTOCOL) |
| 50 | + .set("data_disk_usage_max_disk_size", "10GiB") |
| 51 | + .set("data_disk_usage_percentage_warn_threshold", 98) |
| 52 | + .set("data_disk_usage_percentage_fail_threshold", 98) |
| 53 | + .set("authenticator", "PasswordAuthenticator") |
| 54 | + .set("initial_location_provider", "SimpleLocationProvider") |
| 55 | + ) |
| 56 | + .withTokenSupplier(node -> even.token(node == 3 ? 2 : node)) |
| 57 | + .start() |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + @After |
| 62 | + public void tearDown() throws IOException |
| 63 | + { |
| 64 | + if (cluster != null) |
| 65 | + cluster.close(); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testDiskUsageBroadcasterWhenNodeReplacedShouldRemoveUsageInfo() throws IOException |
| 70 | + { |
| 71 | + GuardrailDiskUsageTest.DiskStateInjection.setState(cluster, 2, DiskUsageState.FULL); |
| 72 | + IInvokableInstance nodeToRemove = cluster.get(2); |
| 73 | + ClusterUtils.stopUnchecked(nodeToRemove); |
| 74 | + IInvokableInstance replacingNode = ClusterUtils.replaceHostAndStart(cluster, nodeToRemove, props -> { |
| 75 | + props.set(CassandraRelevantProperties.BOOTSTRAP_SKIP_SCHEMA_CHECK, true); |
| 76 | + }); |
| 77 | + ClusterUtils.awaitRingJoin(cluster.get(1), replacingNode); |
| 78 | + ClusterUtils.awaitRingJoin(replacingNode, cluster.get(1)); |
| 79 | + boolean hasStuffedOrFullNode = cluster.get(1).callOnInstance(() -> DiskUsageBroadcaster.instance.hasStuffedOrFullNode()); |
| 80 | + Assert.assertFalse(hasStuffedOrFullNode); |
| 81 | + } |
| 82 | +} |
0 commit comments