Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v5.4' into v6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Feb 8, 2024
2 parents 390970b + 682bb13 commit 39de573
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,6 @@ public void store(Object entity, String id) {

public void store(Object entity, String id, IMetadataDictionary metadata) {
try (CleanCloseable check = concurrencyCheck()) {
_lastWriteToStream = new Date();

verifyValidId(id);

executeBeforeStore();
Expand Down Expand Up @@ -789,7 +787,6 @@ protected TimeSeriesBulkInsertBase(BulkInsertOperation operation, String id, Str
protected void appendInternal(Date timestamp, Collection<Double> values, String tag) {
try (CleanCloseable check = _operation.concurrencyCheck()) {
try {
_operation._lastWriteToStream = new Date();
_operation.executeBeforeStore();

if (_first) {
Expand Down Expand Up @@ -955,7 +952,6 @@ public void store(String id, String name, byte[] bytes) {

public void store(String id, String name, byte[] bytes, String contentType) {
try (CleanCloseable check = _operation.concurrencyCheck()) {
_operation._lastWriteToStream = new Date();
_operation.endPreviousCommandIfNeeded();

_operation.executeBeforeStore();
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/net/ravendb/client/ClusterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected ClusterController createRaftCluster(int numberOfNodes, Map<String, Str
Reference<Process> processReference = new Reference<>();
IDocumentStore store = runServerInternal(new TestCloudServiceLocator(customSettings), processReference, null);

Runtime.getRuntime().addShutdownHook(new Thread(() -> killProcess(processReference.value)));
Runtime.getRuntime().addShutdownHook(new Thread(() -> stopServerProcess(processReference.value)));

ClusterNode clusterNode = new ClusterNode();
clusterNode.serverProcess = processReference.value;
Expand Down Expand Up @@ -245,7 +245,7 @@ public DatabasePutResult createDatabase(DatabaseRecord databaseRecord, int repli
public void close() {
for (ClusterNode node : nodes) {
try {
node.serverProcess.destroyForcibly();
RavenTestDriver.stopServerProcess(node.serverProcess);
} catch (Exception e) {
//ignore
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/ravendb/client/RemoteTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ private static void killGlobalServerProcess(boolean secured) {
globalServer = null;
}

killProcess(p);
stopServerProcess(p);
}

public DocumentStore getDocumentStore() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.ravendb.client.serverwide.DatabaseRecord;
import net.ravendb.client.serverwide.DatabaseRecordWithEtag;
import net.ravendb.client.serverwide.operations.CreateDatabaseOperation;
import net.ravendb.client.serverwide.operations.DeleteDatabasesOperation;
import net.ravendb.client.serverwide.operations.GetDatabaseRecordOperation;
import net.ravendb.client.serverwide.operations.configuration.*;
import net.ravendb.client.serverwide.operations.ongoingTasks.DeleteServerWideTaskOperation;
Expand Down Expand Up @@ -75,18 +76,22 @@ public void canCrudServerWideBackup() throws Exception {

// new database includes all server-wide backups
String newDbName = store.getDatabase() + "-testDatabase";
store.maintenance().server().send(new CreateDatabaseOperation(new DatabaseRecord(newDbName)));
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
assertThat(databaseRecord.getPeriodicBackups())
.hasSize(3);

// get by name

ServerWideBackupConfiguration backupConfiguration = store.maintenance().server()
.send(new GetServerWideBackupConfigurationOperation("Backup w/o destinations"));

assertThat(backupConfiguration)
.isNotNull();
try {
store.maintenance().server().send(new CreateDatabaseOperation(new DatabaseRecord(newDbName)));
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
assertThat(databaseRecord.getPeriodicBackups())
.hasSize(3);

// get by name

ServerWideBackupConfiguration backupConfiguration = store.maintenance().server()
.send(new GetServerWideBackupConfigurationOperation("Backup w/o destinations"));

assertThat(backupConfiguration)
.isNotNull();
} finally {
store.maintenance().server().send(new DeleteDatabasesOperation(newDbName, true));
}
} finally {
cleanupServerWideBackups(store);
}
Expand Down
32 changes: 29 additions & 3 deletions src/test/java/net/ravendb/client/driver/RavenTestDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public boolean isDisposed() {

public static boolean debug;

private static Duration _gracefulShutdownTimeout = Duration.ofSeconds(8);

protected void hookLeakedConnectionCheck(DocumentStore store) {
store.addBeforeCloseListener((sender, event) -> {
try {
Expand Down Expand Up @@ -298,14 +300,38 @@ protected static <T> T waitForValue(Supplier<T> act, T expectedValue, Duration t
} while (true);
}

protected static void killProcess(Process p) {
public static void stopServerProcess(Process p) {
if (p != null && p.isAlive()) {
reportInfo("Kill global server");

synchronized (p) {
if (!p.isAlive()) {
return;
}

try {
try (OutputStream stream = p.getOutputStream();
PrintWriter writer = new PrintWriter(stream)) {
writer.println("shutdown no-confirmation");
}

if (p.waitFor(_gracefulShutdownTimeout.toMillis(), TimeUnit.MILLISECONDS)) {
return;
}
} catch (Exception e) {
// ignore
}

try {
p.destroyForcibly().waitFor();
} catch (Exception e) {
// ignore
}
}

try {
p.destroyForcibly();
} catch (Exception e) {
reportError(e);
// ignore
}
}
}
Expand Down
50 changes: 27 additions & 23 deletions src/test/java/net/ravendb/client/test/issues/RavenDB_16367Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,42 @@ public void canLockDatabase() throws Exception {

store.maintenance().server().send(new CreateDatabaseOperation(new DatabaseRecord(databaseName1)));

DatabaseRecordWithEtag databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.UNLOCK);
try {
DatabaseRecordWithEtag databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.UNLOCK);

store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.UNLOCK));
store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.UNLOCK));

databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.UNLOCK);
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.UNLOCK);

store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_ERROR));
store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_ERROR));

databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_ERROR);
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_ERROR);

assertThatThrownBy(() -> store.maintenance().server().send(new DeleteDatabasesOperation(databaseName1, true)))
.hasMessageContaining("cannot be deleted because of the set lock mode");
assertThatThrownBy(() -> store.maintenance().server().send(new DeleteDatabasesOperation(databaseName1, true)))
.hasMessageContaining("cannot be deleted because of the set lock mode");

store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_IGNORE));
store.maintenance().server().send(new SetDatabasesLockOperation(databaseName1, DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_IGNORE));

databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_IGNORE);
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord.getLockMode())
.isEqualTo(DatabaseRecord.DatabaseLockMode.PREVENT_DELETES_IGNORE);

DeleteDatabaseResult result = store.maintenance().server().send(new DeleteDatabasesOperation(databaseName1, true));
assertThat(result.getRaftCommandIndex())
.isEqualTo(-1);
DeleteDatabaseResult result = store.maintenance().server().send(new DeleteDatabasesOperation(databaseName1, true));
assertThat(result.getRaftCommandIndex())
.isEqualTo(-1);

databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord)
.isNotNull();
databaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation(databaseName1));
assertThat(databaseRecord)
.isNotNull();
} finally {
store.maintenance().server().send(new DeleteDatabasesOperation(databaseName1, true));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public DelayCommand(Duration value) {

@Override
public HttpUriRequestBase createRequest(ServerNode node) {
String url = node.getUrl() + "/test/delay?value=" + _value.toMillis();
String url = node.getUrl() + "/admin/test/delay?value=" + _value.toMillis();

return new HttpGet(url);
}
Expand Down
49 changes: 26 additions & 23 deletions src/test/java/net/ravendb/client/test/server/DatabasesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import net.ravendb.client.infrastructure.samples.Genre;
import net.ravendb.client.serverwide.DatabaseRecord;
import net.ravendb.client.serverwide.DatabaseRecordWithEtag;
import net.ravendb.client.serverwide.operations.AddDatabaseNodeOperation;
import net.ravendb.client.serverwide.operations.CreateDatabaseOperation;
import net.ravendb.client.serverwide.operations.DatabasePutResult;
import net.ravendb.client.serverwide.operations.GetDatabaseRecordOperation;
import net.ravendb.client.serverwide.operations.*;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -27,32 +24,38 @@ public void canDisableAndEnableDatabase() throws Exception {
CreateDatabaseOperation databaseOperation = new CreateDatabaseOperation(dbRecord);
store.maintenance().server().send(databaseOperation);

DisableDatabaseToggleResult toggleResult = store.maintenance().server().send(
new ToggleDatabasesStateOperation("enableDisable", true));
try {

assertThat(toggleResult)
.isNotNull();
assertThat(toggleResult.getName())
.isNotNull();

DatabaseRecordWithEtag disabledDatabaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation("enableDisable"));
DisableDatabaseToggleResult toggleResult = store.maintenance().server().send(
new ToggleDatabasesStateOperation("enableDisable", true));

assertThat(disabledDatabaseRecord.isDisabled())
.isTrue();
assertThat(toggleResult)
.isNotNull();
assertThat(toggleResult.getName())
.isNotNull();

// now enable database
DatabaseRecordWithEtag disabledDatabaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation("enableDisable"));

toggleResult = store.maintenance().server().send(
new ToggleDatabasesStateOperation("enableDisable", false));
assertThat(toggleResult)
.isNotNull();
assertThat(toggleResult.getName())
.isNotNull();
assertThat(disabledDatabaseRecord.isDisabled())
.isTrue();

DatabaseRecordWithEtag enabledDatabaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation("enableDisable"));
// now enable database

assertThat(enabledDatabaseRecord.isDisabled())
.isFalse();
toggleResult = store.maintenance().server().send(
new ToggleDatabasesStateOperation("enableDisable", false));
assertThat(toggleResult)
.isNotNull();
assertThat(toggleResult.getName())
.isNotNull();

DatabaseRecordWithEtag enabledDatabaseRecord = store.maintenance().server().send(new GetDatabaseRecordOperation("enableDisable"));

assertThat(enabledDatabaseRecord.isDisabled())
.isFalse();
} finally {
store.maintenance().server().send(new DeleteDatabasesOperation(dbRecord.getDatabaseName(), true));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.ravendb.client.serverwide.DatabaseRecord;
import net.ravendb.client.serverwide.DatabaseRecordWithEtag;
import net.ravendb.client.serverwide.operations.CreateDatabaseOperation;
import net.ravendb.client.serverwide.operations.DeleteDatabasesOperation;
import net.ravendb.client.serverwide.operations.GetDatabaseRecordOperation;
import net.ravendb.client.serverwide.operations.ongoingTasks.*;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -52,32 +53,36 @@ public void canStoreServerWideExternalReplication() throws Exception {

// the configuration is applied to new databases
String newDbName = store.getDatabase() + "-testDatabase";
store.maintenance().server().send(new CreateDatabaseOperation(new DatabaseRecord(newDbName)));
List<ExternalReplication> externalReplications = record1.getExternalReplications();
assertThat(externalReplications)
.hasSize(1);

DatabaseRecordWithEtag record2 = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
validateConfiguration(serverWideConfiguration, record2.getExternalReplications().get(0), newDbName);

// update the external replication configuration

putConfiguration.setTopologyDiscoveryUrls(new String[]{store.getUrls()[0], "http://localhost:8080"});
putConfiguration.setName(serverWideConfiguration.getName());

result = store.maintenance().server().send(new PutServerWideExternalReplicationOperation(putConfiguration));
serverWideConfiguration = store.maintenance().server().send(new GetServerWideExternalReplicationOperation(result.getName()));
validateServerWideConfiguration(serverWideConfiguration, putConfiguration);

record1 = store.maintenance().server().send(new GetDatabaseRecordOperation(store.getDatabase()));
assertThat(record1.getExternalReplications())
.hasSize(1);
validateConfiguration(serverWideConfiguration, record1.getExternalReplications().get(0), store.getDatabase());

record2 = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
assertThat(record2.getExternalReplications())
.hasSize(1);
validateConfiguration(serverWideConfiguration, record2.getExternalReplications().get(0), newDbName);
try {
store.maintenance().server().send(new CreateDatabaseOperation(new DatabaseRecord(newDbName)));
List<ExternalReplication> externalReplications = record1.getExternalReplications();
assertThat(externalReplications)
.hasSize(1);

DatabaseRecordWithEtag record2 = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
validateConfiguration(serverWideConfiguration, record2.getExternalReplications().get(0), newDbName);

// update the external replication configuration

putConfiguration.setTopologyDiscoveryUrls(new String[]{store.getUrls()[0], "http://localhost:8080"});
putConfiguration.setName(serverWideConfiguration.getName());

result = store.maintenance().server().send(new PutServerWideExternalReplicationOperation(putConfiguration));
serverWideConfiguration = store.maintenance().server().send(new GetServerWideExternalReplicationOperation(result.getName()));
validateServerWideConfiguration(serverWideConfiguration, putConfiguration);

record1 = store.maintenance().server().send(new GetDatabaseRecordOperation(store.getDatabase()));
assertThat(record1.getExternalReplications())
.hasSize(1);
validateConfiguration(serverWideConfiguration, record1.getExternalReplications().get(0), store.getDatabase());

record2 = store.maintenance().server().send(new GetDatabaseRecordOperation(newDbName));
assertThat(record2.getExternalReplications())
.hasSize(1);
validateConfiguration(serverWideConfiguration, record2.getExternalReplications().get(0), newDbName);
} finally {
store.maintenance().server().send(new DeleteDatabasesOperation(newDbName, true));
}
} finally {
store.maintenance().server().send(new DeleteServerWideTaskOperation(serverWideConfiguration.getName(), OngoingTaskType.REPLICATION));
}
Expand Down

0 comments on commit 39de573

Please sign in to comment.