Skip to content

Commit

Permalink
Switch to K instead of k for kilo
Browse files Browse the repository at this point in the history
Fix test failures
  • Loading branch information
blambov committed Jul 6, 2023
1 parent b6c8025 commit b6de426
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 69 deletions.
8 changes: 4 additions & 4 deletions src/java/org/apache/cassandra/utils/FBUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,14 +829,14 @@ public static <T> CloseableIterator<T> closeableIterator(Iterator<T> iterator)
return new WrappedCloseableIterator<T>(iterator);
}

final static String UNIT_PREFIXES = "qryzafpnum kMGTPEZYRQ";
final static String UNIT_PREFIXES = "qryzafpnum KMGTPEZYRQ";
final static int UNIT_PREFIXES_BASE = UNIT_PREFIXES.indexOf(' ');
final static Pattern BASE_NUMBER_PATTERN = Pattern.compile("NaN|[+-]?Infinity|[+-]?\\d+(\\.\\d+)?([eE]([+-]?)\\d+)?");
final static Pattern BINARY_EXPONENT = Pattern.compile("\\*2\\^([+-]?\\d+)");

/**
* Convert the given size in bytes to a human-readable value using binary (i.e. 2^10-based) modifiers.
* For example, 1.000kiB, 2.100GiB etc., up to 8.000 EiB.
* For example, 1.000KiB, 2.100GiB etc., up to 8.000 EiB.
* @param size Number to convert.
*/
public static String prettyPrintMemory(long size)
Expand All @@ -846,7 +846,7 @@ public static String prettyPrintMemory(long size)

/**
* Convert the given size in bytes to a human-readable value using binary (i.e. 2^10-based) modifiers.
* For example, 1.000kiB, 2.100GiB etc., up to 8.000 EiB.
* For example, 1.000KiB, 2.100GiB etc., up to 8.000 EiB.
* @param size Number to convert.
* @param separator Separator between the number and the (modified) unit.
*/
Expand All @@ -866,7 +866,7 @@ public static String prettyPrintMemory(long size, String separator)
* Convert the given value to a human-readable string using binary (i.e. 2^10-based) modifiers.
* If the number is outside the modifier range (i.e. < 1 qi or > 1 Qi), it will be printed as v*2^e where e is a
* multiple of 10 with sign.
* For example, 1.000kiB, 2.100 miB/s, 7.006*2^+150, -Infinity.
* For example, 1.000KiB, 2.100 miB/s, 7.006*2^+150, -Infinity.
* @param value Number to convert.
* @param separator Separator between the number and the (modified) unit.
*/
Expand Down
7 changes: 7 additions & 0 deletions test/unit/org/apache/cassandra/cql3/CQLTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,13 @@ public void compact()
store.forceMajorCompaction();
}

public void forceCompactAll()
{
ColumnFamilyStore store = getCurrentColumnFamilyStore();
if (store != null)
FBUtilities.waitOnFuture(Util.compactAll(store, FBUtilities.nowInSeconds()));
}

public void disableCompaction()
{
disableCompaction(KEYSPACE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ public void testStandardCompactionTaskCancellation() throws Throwable

for (int i = 0; i < 10; i++)
{
execute("insert into %s (id, something) values (?,?)", i, i);
for (int j = 0; j < 3; ++j) // write more than once to ensure overlap for UCS
execute("insert into %s (id, something) values (?,?)", i * (j+1), i + j);
flush();
}
AbstractCompactionTask ct = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.cassandra.schema.CompactionParams;
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.utils.ByteBufferUtil;
import org.apache.cassandra.utils.FBUtilities;

import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -64,17 +65,17 @@ private void testCompaction(String columnFamilyName, int insertsPerTable)
Set<String> inserted = new HashSet<>();
for (int j = 0; j < insertsPerTable; j++) {
String key = String.valueOf(j);
new RowUpdateBuilder(store.metadata(), j, key)
new RowUpdateBuilder(store.metadata(), j, key)
.clustering("0")
.add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER)
.build()
.applyUnsafe();

inserted.add(key);
inserted.add(key);
Util.flush(store);
assertEquals(inserted.size(), Util.getAll(Util.cmd(store).build()).size());
}
CompactionManager.instance.performMaximal(store, false);
FBUtilities.waitOnFuture(Util.compactAll(store, FBUtilities.nowInSeconds()));
assertEquals(1, store.getLiveSSTables().size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ public void testNoExpire() throws InterruptedException, IOException
.add("col311", ByteBufferUtil.EMPTY_BYTE_BUFFER)
.build()
.applyUnsafe();
// also write to other key to ensure overlap for UCS
new RowUpdateBuilder(cfs.metadata(), timestamp, 1, key)
.add("col7", ByteBufferUtil.EMPTY_BYTE_BUFFER)
.build()
.applyUnsafe();

Util.flush(cfs);
Thread.sleep(2000); // wait for ttl to expire
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.BeforeClass;
import org.junit.Test;

import org.apache.cassandra.Util;
import org.apache.cassandra.config.Config;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.cql3.CQLTester;
Expand Down Expand Up @@ -117,7 +118,7 @@ public void lz4FlushTest() throws Throwable
});

// Should compact to LZ4 "fast"
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand All @@ -142,7 +143,7 @@ public void lz4hcFlushTest() throws Throwable
});

// Should compact to LZ4 "high" mode
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand All @@ -165,7 +166,7 @@ public void zstdFlushTest() throws Throwable
});

// Should compact to Zstd
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand All @@ -187,7 +188,7 @@ public void deflateFlushTest() throws Throwable
});

// Should compact to Deflate
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand All @@ -210,7 +211,7 @@ public void useNoCompressorOnFlushTest() throws Throwable
});

// Should compact to LZ4
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand Down Expand Up @@ -247,7 +248,7 @@ public void zstdTableFlushTest() throws Throwable
});

// Should compact to Zstd
compact();
forceCompactAll();

sstables = store.getLiveSSTables();
assertEquals(sstables.size(), 1);
Expand Down
Loading

0 comments on commit b6de426

Please sign in to comment.