Skip to content

Commit

Permalink
JAMES-2076 remove useless lightweight condition
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa committed Jun 28, 2017
1 parent 3562b88 commit 416e310
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Expand Up @@ -49,6 +49,7 @@
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.querybuilder.Select;
import com.github.steveash.guavate.Guavate;

public class CassandraSieveDAO {

Expand Down Expand Up @@ -116,7 +117,7 @@ public CompletableFuture<List<ScriptSummary>> listScripts(String user) {
.map(row -> new ScriptSummary(
row.getString(SCRIPT_NAME),
row.getBool(IS_ACTIVE)))
.collect(Collectors.toList()));
.collect(Guavate.toImmutableList()));
}

public CompletableFuture<Boolean> updateScriptActivation(String user, String scriptName, boolean active) {
Expand Down
Expand Up @@ -89,14 +89,12 @@ public CassandraSieveQuotaDAO(Session session) {
deleteClusterQuotaStatement = session.prepare(
delete()
.from(CassandraSieveClusterQuotaTable.TABLE_NAME)
.where(eq(CassandraSieveClusterQuotaTable.NAME, bindMarker(CassandraSieveClusterQuotaTable.NAME)))
.ifExists());
.where(eq(CassandraSieveClusterQuotaTable.NAME, bindMarker(CassandraSieveClusterQuotaTable.NAME))));

deleteUserQuotaStatement = session.prepare(
delete()
.from(CassandraSieveQuotaTable.TABLE_NAME)
.where(eq(CassandraSieveQuotaTable.USER_NAME, bindMarker(CassandraSieveQuotaTable.USER_NAME)))
.ifExists());
.where(eq(CassandraSieveQuotaTable.USER_NAME, bindMarker(CassandraSieveQuotaTable.USER_NAME))));
}

public CompletableFuture<Long> spaceUsedBy(String user) {
Expand Down Expand Up @@ -128,8 +126,8 @@ public CompletableFuture<Void> setQuota(long quota) {
.setString(CassandraSieveClusterQuotaTable.NAME, CassandraSieveClusterQuotaTable.DEFAULT_NAME));
}

public CompletableFuture<Boolean> removeQuota() {
return cassandraAsyncExecutor.executeReturnApplied(
public CompletableFuture<Void> removeQuota() {
return cassandraAsyncExecutor.executeVoid(
deleteClusterQuotaStatement.bind()
.setString(CassandraSieveClusterQuotaTable.NAME, CassandraSieveClusterQuotaTable.DEFAULT_NAME));
}
Expand All @@ -148,8 +146,8 @@ public CompletableFuture<Void> setQuota(String user, long quota) {
.setString(CassandraSieveQuotaTable.USER_NAME, user));
}

public CompletableFuture<Boolean> removeQuota(String user) {
return cassandraAsyncExecutor.executeReturnApplied(
public CompletableFuture<Void> removeQuota(String user) {
return cassandraAsyncExecutor.executeVoid(
deleteUserQuotaStatement.bind()
.setString(CassandraSieveQuotaTable.USER_NAME, user));
}
Expand Down
Expand Up @@ -237,9 +237,7 @@ public void setQuota(long quota) {

@Override
public void removeQuota() throws QuotaNotFoundException {
if (!cassandraSieveQuotaDAO.removeQuota().join()) {
throw new QuotaNotFoundException();
}
cassandraSieveQuotaDAO.removeQuota().join();
}

@Override
Expand All @@ -266,9 +264,7 @@ public void setQuota(String user, long quota) {

@Override
public void removeQuota(String user) throws QuotaNotFoundException {
if (!cassandraSieveQuotaDAO.removeQuota(user).join()) {
throw new QuotaNotFoundException();
}
cassandraSieveQuotaDAO.removeQuota(user).join();
}

}
Expand Up @@ -420,7 +420,7 @@ public long getQuota() throws QuotaNotFoundException, StorageException {
public synchronized void removeQuota() throws QuotaNotFoundException, StorageException {
File file = getQuotaFile();
if (!file.exists()) {
throw new QuotaNotFoundException("No default quota");
return;
}
try {
FileUtils.forceDelete(file);
Expand Down Expand Up @@ -475,7 +475,7 @@ public void removeQuota(String user) throws QuotaNotFoundException, StorageExcep
synchronized (lock) {
File file = getQuotaFile(user);
if (!file.exists()) {
throw new QuotaNotFoundException("No quota for user: " + user);
return;
}
try {
FileUtils.forceDelete(file);
Expand Down
Expand Up @@ -303,11 +303,16 @@ public void hasQuotaShouldReturnTrueWhenUserHaveQuota() throws Exception {
assertThat(sieveRepository.hasQuota(USER)).isTrue();
}

@Test(expected = QuotaNotFoundException.class)
public void removeQuotaShouldThrowIfRepositoryDoesNotHaveQuota() throws Exception {
@Test
public void removeQuotaShouldNotThrowIfRepositoryDoesNotHaveQuota() throws Exception {
sieveRepository.removeQuota();
}

@Test
public void removeUserQuotaShouldNotThrowWhenAbsent() throws Exception {
sieveRepository.removeQuota(USER);
}

@Test
public void removeQuotaShouldWorkOnRepositories() throws Exception {
sieveRepository.setQuota(DEFAULT_QUOTA);
Expand Down

0 comments on commit 416e310

Please sign in to comment.