forked from apache/cassandra
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CNDB-11544 Add coordinator MEMORY_BYTES sensor for reads
- Loading branch information
Showing
4 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,5 +28,6 @@ public enum Type | |
READ_BYTES, | ||
|
||
WRITE_BYTES, | ||
INDEX_WRITE_BYTES | ||
INDEX_WRITE_BYTES, | ||
MEMORY_BYTES | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
test/unit/org/apache/cassandra/sensors/CoordinatorSensorsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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.sensors; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import org.apache.cassandra.config.CassandraRelevantProperties; | ||
import org.apache.cassandra.cql3.CQLTester; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class CoordinatorSensorsTest extends CQLTester | ||
{ | ||
@BeforeClass | ||
public static void setupClass() | ||
{ | ||
CassandraRelevantProperties.SENSORS_FACTORY.setString(ActiveSensorsFactory.class.getName()); | ||
// a workaround to force sensors registry to initialize (i.e. subscribe to SchemaChangeListener) before the | ||
// test creates the keyspace and tables | ||
SensorsRegistry.instance.clear(); | ||
} | ||
|
||
@Test | ||
public void testReadSensors() | ||
{ | ||
createTable("create table %s (pk int, ck int, v text, primary key(pk, ck))"); | ||
Context context = Context.from(currentTableMetadata()); | ||
Optional<Sensor> memorySensor = SensorsRegistry.instance.getSensor(context, Type.MEMORY_BYTES); | ||
assertThat(memorySensor).isEmpty(); | ||
|
||
executeNet("insert into %s (pk, ck, v) values (1, 1, 'v1')"); | ||
executeNet("select * from %s where pk = 1"); | ||
memorySensor = SensorsRegistry.instance.getSensor(context, Type.MEMORY_BYTES); | ||
assertThat(memorySensor).isPresent(); | ||
double memoryBytes = memorySensor.get().getValue(); | ||
assertThat(memoryBytes).isGreaterThan(0); | ||
|
||
executeNet("select * from %s where pk = 1"); | ||
assertThat(memorySensor.get().getValue()).isEqualTo(memoryBytes * 2); | ||
} | ||
|
||
@Test | ||
public void testRangeReadSensors() | ||
{ | ||
createTable("create table %s (pk int, ck int, v text, primary key(pk, ck))"); | ||
Context context = Context.from(currentTableMetadata()); | ||
Optional<Sensor> memorySensor = SensorsRegistry.instance.getSensor(context, Type.MEMORY_BYTES); | ||
assertThat(memorySensor).isEmpty(); | ||
|
||
executeNet("insert into %s (pk, ck, v) values (1, 1, 'v1')"); | ||
executeNet("insert into %s (pk, ck, v) values (1, 2, 'v2')"); | ||
executeNet("insert into %s (pk, ck, v) values (1, 3, 'v3')"); | ||
executeNet("select * from %s"); | ||
memorySensor = SensorsRegistry.instance.getSensor(context, Type.MEMORY_BYTES); | ||
assertThat(memorySensor).isPresent(); | ||
double memoryBytes = memorySensor.get().getValue(); | ||
assertThat(memoryBytes).isGreaterThan(0); | ||
|
||
executeNet("select * from %s"); | ||
assertThat(memorySensor.get().getValue()).isEqualTo(memoryBytes * 2); | ||
} | ||
} |