Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 3fe7a83

Browse files
committed
#89 Now always creating forests when a database is created/updated
1 parent 91a4597 commit 3fe7a83

File tree

6 files changed

+73
-28
lines changed

6 files changed

+73
-28
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/build/
55
.project
66
.classpath
7+
.idea
78
src/test/resources/user.properties
89
setenv.bat
910
src/test/resources/scaffold-test/

src/main/java/com/marklogic/appdeployer/command/databases/DeployContentDatabasesCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void execute(CommandContext context) {
5151
DatabaseManager dbMgr = new DatabaseManager(context.getManageClient());
5252
String json = tokenReplacer.replaceTokens(payload, appConfig, true);
5353
SaveReceipt receipt = dbMgr.save(json);
54-
createForestsIfDatabaseWasJustCreated(receipt, context);
54+
buildDeployForestsCommand(receipt, context).execute(context);
5555
}
5656
}
5757
}

src/main/java/com/marklogic/appdeployer/command/databases/DeployDatabaseCommand.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void execute(CommandContext context) {
8181
String json = tokenReplacer.replaceTokens(payload, appConfig, false);
8282
DatabaseManager dbMgr = new DatabaseManager(context.getManageClient());
8383
SaveReceipt receipt = dbMgr.save(json);
84-
createForestsIfDatabaseWasJustCreated(receipt, context);
84+
buildDeployForestsCommand(receipt, context).execute(context);
8585
}
8686
}
8787

@@ -114,16 +114,6 @@ protected String getPayload(CommandContext context) {
114114
}
115115
}
116116

117-
protected void createForestsIfDatabaseWasJustCreated(SaveReceipt receipt, CommandContext context) {
118-
// Location header is only set when the database has just been created
119-
if (receipt.hasLocationHeader()) {
120-
if (logger.isInfoEnabled()) {
121-
logger.info("Creating forests for newly created database: " + receipt.getResourceId());
122-
}
123-
buildDeployForestsCommand(receipt, context).execute(context);
124-
}
125-
}
126-
127117
/**
128118
* Allows for how an instance of DeployForestsCommand is built to be overridden by a subclass.
129119
*

src/main/java/com/marklogic/appdeployer/command/restapis/DeployRestApiServersCommand.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public DeployRestApiServersCommand() {
2929
setExecuteSortOrder(SortOrderConstants.DEPLOY_REST_API_SERVERS);
3030
}
3131

32+
public DeployRestApiServersCommand(boolean deleteContentDatabase) {
33+
this();
34+
this.deleteContentDatabase = deleteContentDatabase;
35+
}
36+
3237
@Override
3338
public Integer getUndoSortOrder() {
3439
return SortOrderConstants.DELETE_REST_API_SERVERS;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.marklogic.appdeployer.command.databases;
2+
3+
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.mgmt.databases.DatabaseManager;
5+
import com.marklogic.rest.util.Fragment;
6+
import org.junit.After;
7+
import org.junit.Test;
8+
9+
import java.io.File;
10+
import java.util.List;
11+
12+
/**
13+
* Verifies support for bumping up the number of content forests and then re-deploying. Does not yet support lowering
14+
* the number of content forests and expecting the existing ones to be detached/deleted.
15+
*/
16+
public class UpdateForestCountTest extends AbstractAppDeployerTest {
17+
18+
@Test
19+
public void test() {
20+
appConfig.getConfigDir().setBaseDir(new File("src/test/resources/sample-app/db-only-config"));
21+
DatabaseManager mgr = new DatabaseManager(manageClient);
22+
23+
initializeAppDeployer(new DeployContentDatabasesCommand());
24+
25+
appConfig.setContentForestsPerHost(1);
26+
appDeployer.deploy(appConfig);
27+
assertEquals("Should only have 1 forest", 1, mgr.getForestIds(appConfig.getContentDatabaseName()).size());
28+
29+
appConfig.setContentForestsPerHost(2);
30+
appDeployer.deploy(appConfig);
31+
assertEquals("Should now have 2 forests", 2, mgr.getForestIds(appConfig.getContentDatabaseName()).size());
32+
33+
appDeployer.deploy(appConfig);
34+
assertEquals("Should still have 2 forests", 2, mgr.getForestIds(appConfig.getContentDatabaseName()).size());
35+
36+
appConfig.setContentForestsPerHost(1);
37+
appDeployer.deploy(appConfig);
38+
assertEquals("Should still have 2 forests, we don't yet support deleting forests when the number drops", 2, mgr.getForestIds(appConfig.getContentDatabaseName()).size());
39+
}
40+
41+
@After
42+
public void teardown() {
43+
undeploySampleApp();
44+
}
45+
}

src/test/java/com/marklogic/appdeployer/command/modules/LoadModulesTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
package com.marklogic.appdeployer.command.modules;
22

3-
import java.io.File;
4-
5-
import org.junit.After;
6-
import org.junit.Before;
7-
import org.junit.Test;
8-
93
import com.marklogic.appdeployer.AbstractAppDeployerTest;
4+
import com.marklogic.appdeployer.command.databases.DeployContentDatabasesCommand;
5+
import com.marklogic.appdeployer.command.databases.DeployTriggersDatabaseCommand;
106
import com.marklogic.appdeployer.command.restapis.DeployRestApiServersCommand;
117
import com.marklogic.client.modulesloader.impl.AssetFileFilter;
128
import com.marklogic.junit.PermissionsFragment;
139
import com.marklogic.xcc.template.XccTemplate;
10+
import org.junit.After;
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
14+
import java.io.File;
1415

1516
public class LoadModulesTest extends AbstractAppDeployerTest {
1617

1718
private XccTemplate xccTemplate;
1819

1920
@Before
2021
public void setup() {
21-
xccTemplate = newModulesXccTemplate();
22+
xccTemplate = new XccTemplate(format("xcc://%s:%s@%s:8000/%s", "admin",
23+
"admin", appConfig.getHost(), appConfig.getModulesDatabaseName()));
2224
deleteModuleTimestampsFile();
2325
}
2426

@@ -31,7 +33,7 @@ public void teardown() {
3133
public void loadModulesFromMultiplePaths() {
3234
appConfig.getModulePaths().add("src/test/resources/sample-app/build/mlRestApi/some-library/ml-modules");
3335

34-
initializeAppDeployer(new DeployRestApiServersCommand(), new LoadModulesCommand());
36+
initializeAppDeployer(new DeployRestApiServersCommand(true), new LoadModulesCommand());
3537

3638
appDeployer.deploy(appConfig);
3739

@@ -46,7 +48,7 @@ public void loadModulesWithCustomPermissions() {
4648
LoadModulesCommand c = new LoadModulesCommand();
4749
appConfig.setModulePermissions(appConfig.getModulePermissions() + ",app-user,execute");
4850

49-
initializeAppDeployer(new DeployRestApiServersCommand(), c);
51+
initializeAppDeployer(new DeployRestApiServersCommand(true), c);
5052

5153
appDeployer.deploy(appConfig);
5254

@@ -63,23 +65,25 @@ public void loadModulesWithAssetFileFilter() {
6365
LoadModulesCommand c = new LoadModulesCommand();
6466
appConfig.setAssetFileFilter(new TestFileFilter());
6567

66-
initializeAppDeployer(new DeployRestApiServersCommand(), c);
68+
initializeAppDeployer(new DeployRestApiServersCommand(true), c);
6769
appDeployer.deploy(appConfig);
68-
70+
6971
assertEquals("true", xccTemplate.executeAdhocQuery("doc-available('/ext/lib/test.xqy')"));
7072
assertEquals("false", xccTemplate.executeAdhocQuery("doc-available('/ext/lib/test2.xqy')"));
7173
}
7274

7375
@Test
7476
public void testServerExists() {
77+
appConfig.getConfigDir().setBaseDir(new File(("src/test/resources/sample-app/db-only-config")));
7578
appConfig.setTestRestPort(8541);
76-
initializeAppDeployer(new DeployRestApiServersCommand(), new LoadModulesCommand());
79+
initializeAppDeployer(new DeployRestApiServersCommand(true), new LoadModulesCommand());
80+
7781
appDeployer.deploy(appConfig);
7882

79-
assertEquals("true", xccTemplate
80-
.executeAdhocQuery("fn:doc-available('/Default/sample-app/rest-api/options/sample-app-options.xml')"));
81-
assertEquals("true", xccTemplate.executeAdhocQuery(
82-
"fn:doc-available('/Default/sample-app-test/rest-api/options/sample-app-options.xml')"));
83+
String[] uris = new String[]{"/Default/sample-app/rest-api/options/sample-app-options.xml", "/Default/sample-app/rest-api/options/sample-app-options.xml"};
84+
for (String uri : uris) {
85+
assertEquals("true", xccTemplate.executeAdhocQuery(format("doc-available('%s')", uri)));
86+
}
8387
}
8488

8589
private void assertModuleExistsWithDefaultPermissions(String message, String uri) {

0 commit comments

Comments
 (0)