@Test
public void maxClusters() throws Exception {
log(" * Create database");
try (ODatabaseDocumentTx db = createDatabase()) {
OSchema schema = db.getMetadata().getSchema();
OClass type = schema.createClass("Message");
type.setClusterSelection(ODefaultClusterSelectionStrategy.NAME);
type.createProperty("text", OType.STRING);
}
try (ODatabaseDocumentTx db = openDatabase()) {
OSchema schema = db.getMetadata().getSchema();
OClass type = schema.getClass("Message");
int previousClusterId = type.getDefaultClusterId();
for (int c = 0; c < 32_767 - 10; c++) {
log("Previous cluster-id: {}", previousClusterId);
log(" * Create new cluster #{}", c);
// create new cluster
String newClusterName = String.format("Message_%s", System.currentTimeMillis());
type.addCluster(newClusterName);
int newClusterId = db.getClusterIdByName(newClusterName);
type.setDefaultClusterId(newClusterId);
log("New cluster; id: {}, name: {}", newClusterId, newClusterName);
log(" * create records");
for (int i = 0; i < 1; i++) {
db.newInstance("Message")
.field("text", String.format("Hi %s", System.currentTimeMillis()))
.save();
}
log(" * truncating cluster: id: {}", previousClusterId);
type.removeClusterId(previousClusterId);
db.dropCluster(previousClusterId, false);
previousClusterId = newClusterId;
}
}
log(" * dump clusters");
try (ODatabaseDocumentTx db = openDatabase()) {
OSchema schema = db.getMetadata().getSchema();
OClass type = schema.getClass("Message");
for (int clusterId : type.getClusterIds()) {
String clusterName = db.getClusterNameById(clusterId);
log("Cluster; id: {}, name: {}", clusterId, clusterName);
for (ODocument doc : db.browseCluster(clusterName)) {
log("Document: {}", doc);