Skip to content

Commit

Permalink
fix: Fixed MB to bytes conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Feb 29, 2024
1 parent 4c5759d commit 908a05a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ public class Database {

public static final String DEFAULT_NAME = "redis-enterprise-admin-db";

public static final long MB_TO_BYTES = 1024 ^ 2;
public static final long KILO = 1024;
public static final long MEGA = KILO * KILO;
public static final long GIGA = MEGA * KILO;
public static final long DEFAULT_MEMORY_MB = 100;
public static final long DEFAULT_MEMORY = DEFAULT_MEMORY_MB * MB_TO_BYTES;
public static final long DEFAULT_MEMORY = DEFAULT_MEMORY_MB * MEGA;
public static final int DEFAULT_CLUSTER_SHARD_COUNT = 3;

public static List<String> defaultShardKeyRegexes() {
Expand Down Expand Up @@ -348,8 +350,16 @@ public Builder memory(long memory) {
return this;
}

public Builder memoryKB(long memory) {
return memory(memory * KILO);
}

public Builder memoryMB(long memory) {
return memory(memory * MB_TO_BYTES);
return memory(memory * MEGA);
}

public Builder memoryGB(long memory) {
return memory(memory * GIGA);
}

public Builder port(Integer port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ void deleteDatabase() throws ParseException, GeneralSecurityException, IOExcepti

@Test
void createDatabaseException() throws ParseException, IOException {
Assertions.assertThrows(HttpResponseException.class, () -> admin.createDatabase(Database.builder()
.name("DatabaseCreateExceptionTestDB").memory(999000 * Database.MB_TO_BYTES).build()));
long memory = 999 * Database.GIGA;
Assertions.assertThrows(HttpResponseException.class, () -> admin
.createDatabase(Database.builder().name("DatabaseCreateExceptionTestDB").memory(memory).build()));
}

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.redis.enterprise;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

@Disabled // @EnabledIfEnvironmentVariable(named = RedisEnterpriseServer.ENV_HOST, matches
// = ".*")
import com.redis.testcontainers.RedisEnterpriseServer;

@EnabledIfEnvironmentVariable(named = RedisEnterpriseServer.ENV_HOST, matches = ".*")
class ServerAdminTests extends AbstractAdminTests {

@Override
protected Admin admin() {
Admin admin = new Admin();
// TODO admin.withHost(System.getenv(RedisEnterpriseServer.ENV_HOST));
admin.withHost(System.getenv(RedisEnterpriseServer.ENV_HOST));
return admin;
}

Expand Down

0 comments on commit 908a05a

Please sign in to comment.