Skip to content

Commit add022f

Browse files
committed
Merge pull request #217 from surevine/issues/214
Prevent purging of remote data on server start unless specifically requested
2 parents 07e4456 + 1e845e6 commit add022f

5 files changed

Lines changed: 95 additions & 7 deletions

File tree

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ psql -h 127.0.0.1 --username buddycloud_server -d buddycloud_server -c "select *
5151
~~~~
5252
If you got an output similar to (or exactly like) this, you're good to go.
5353

54+
## Configuration
55+
56+
Please see [the example configuration file](https://github.com/buddycloud/buddycloud-server-java/blob/master/configuration.properties.example) for an example.
57+
58+
| Property | Default value | Required | Description |
59+
| ----------------------------------------- | -------------- | :--------: |---------------------------------------------- |
60+
| xmpp.host | || The XMPP server host (IP address or hostname) |
61+
| xmpp.port | || XMPP server component port |
62+
| xmpp.secretkey | || Component secret |
63+
| server.domain | || XMPP server domain |
64+
| server.domain.channels | || Buddycloud server domain / Component address |
65+
| server.domain.topics | | | Topics component address |
66+
| jdbc.proxool.alias | || Database connection name |
67+
| jdbc.proxool.driver-url | || Database connection string |
68+
| jdbc.proxool.driver-class | || Database connection class |
69+
| jdbc.user | || Database username |
70+
| jdbc.password | || Database password |
71+
| jdbc.proxool.maximum-connection-count | || Database connection pool size |
72+
| jdbc.proxool.house-keeping-test-sql | || Database house keeping test |
73+
| users.admin | | | Admin users (list of jids). Are sent all notifications and are able to see everything in **/firehose** |
74+
| notifications.sendTo | | | List of JIDs to send event messages to |
75+
| notifications.connected | | | Send event of component connecting to XMPP server |
76+
| channels.autosubscribe | | | A list of channels (local or remote) to which to subscribe new users. Only the base JID is required. __Note:__ channels will not be created - they must already exist
77+
| channels.autosubscribe.autoapprove | | | If any of the 'channels.autosubscribe' channels are private local channels, then whether to automatically approve the user. __Note:__ This will only work on local private channels |
78+
| channel.configuration.default.accessmodel | open | | The default access model for new nodes |
79+
| channel.configuration.default.affiliation | member | | The default affiliation for new nodes |
80+
| channel.configuration.[**posts** or **status** or **geo.next**, etc].accessmodel | | | Override default access model on the node type |
81+
| channel.configuration.[**posts** or **status** or **geo.next**, etc].affiliation | | | Override default affiliation on the node type |
82+
| channel.configuration.[**posts** or **status** or **geo.next**, etc].title | %jid%'s status | | Override default node title on the node type |
83+
| channel.configuration.[**posts** or **status** or **geo.next**, etc].description | %jid%'s status | | Override default node description on the node type |
84+
| discovery.dns.enabled | true | | Allow DNS discovery of other channel servers |
85+
| sync.purge-on-start | false | | Purge remote data on server start |
86+
5487
## Additional content-type plugins
5588
The buddycloud server supports validation of custom content types by means of a plugin system. By default the buddycloud server supports Atom content. Additional content types can be supported by creating an appropriate validator and packaging it as a plugin.
5689

src/main/java/org/buddycloud/channelserver/ChannelsEngine.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private void sendConnectionNotification(JID jid2) throws ComponentException {
8484
}
8585

8686
private void serverSync() {
87-
serverSync = new ServerSync(channelManagerFactory, inQueue, outQueue);
87+
serverSync = new ServerSync(channelManagerFactory, inQueue, outQueue, configuration);
8888
serverSync.start();
8989
}
9090

src/main/java/org/buddycloud/channelserver/Configuration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class Configuration extends Properties {
4141

4242
private static final String CONFIGURATION_FILE = "configuration.properties";
4343

44+
public static final String PURGE_REMOTE_ON_START = "sync.purge-on-start";
45+
4446
private static Configuration instance = null;
4547

4648
private Collection<JID> adminUsers = new ArrayList<JID>();

src/main/java/org/buddycloud/channelserver/sync/ServerSync.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.concurrent.LinkedBlockingQueue;
55

66
import org.apache.log4j.Logger;
7+
import org.buddycloud.channelserver.Configuration;
78
import org.buddycloud.channelserver.channel.ChannelManager;
89
import org.buddycloud.channelserver.channel.ChannelManagerFactory;
910
import org.buddycloud.channelserver.db.exception.NodeStoreException;
@@ -16,26 +17,34 @@ public class ServerSync {
1617
private ChannelManager channelManager;
1718
private BlockingQueue<Packet> inQueue;
1819
private BlockingQueue<Packet> outQueue;
20+
private Configuration configuration;
1921

2022
private Logger logger = Logger.getLogger(ServerSync.class);
21-
23+
2224
public ServerSync(ChannelManagerFactory channelManagerFactory,
23-
BlockingQueue<Packet> outQueue, BlockingQueue<Packet> inQueue) {
25+
BlockingQueue<Packet> outQueue, BlockingQueue<Packet> inQueue,
26+
Configuration configuration) {
2427
this.channelManager = channelManagerFactory.create();
2528
this.outQueue = outQueue;
2629
this.inQueue = inQueue;
30+
this.configuration = configuration;
2731
}
2832

2933
public void start() {
3034
try {
31-
deleteFederatedChannelCache();
32-
channelManager.close();
35+
deleteFederatedChannelCache();
36+
channelManager.close();
3337
} catch (NodeStoreException e) {
3438
logger.error(e);
3539
}
3640
}
3741

3842
private void deleteFederatedChannelCache() throws NodeStoreException {
43+
Boolean purge = Boolean.valueOf(configuration.getProperty(
44+
Configuration.PURGE_REMOTE_ON_START, "false"));
45+
if (false == purge) {
46+
return;
47+
}
3948
channelManager.deleteRemoteData();
4049
}
4150
}

src/test/java/org/buddycloud/channelserver/sync/ServerSyncTest.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.concurrent.BlockingQueue;
44
import java.util.concurrent.LinkedBlockingQueue;
55

6+
import org.buddycloud.channelserver.Configuration;
7+
import org.buddycloud.channelserver.channel.ChannelManager;
68
import org.buddycloud.channelserver.channel.ChannelManagerFactory;
79
import org.buddycloud.channelserver.packetHandler.iq.IQTestHandler;
810
import org.junit.Before;
@@ -15,18 +17,60 @@ public class ServerSyncTest extends IQTestHandler {
1517
private BlockingQueue<Packet> outQueue = new LinkedBlockingQueue<Packet>();
1618
private BlockingQueue<Packet> inQueue = new LinkedBlockingQueue<Packet>();
1719
private ChannelManagerFactory channelManagerFactory;
20+
private ChannelManager channelManager;
1821
private ServerSync serverSync;
22+
private Configuration configuration;
1923

2024
@Before
2125
public void setUp() throws Exception {
2226

27+
configuration = Mockito.mock(Configuration.class);
28+
29+
channelManager = Mockito.mock(ChannelManager.class);
2330
channelManagerFactory = Mockito.mock(ChannelManagerFactory.class);
24-
serverSync = new ServerSync(channelManagerFactory, outQueue, inQueue);
31+
Mockito.when(channelManagerFactory.create()).thenReturn(channelManager);
32+
serverSync = new ServerSync(channelManagerFactory, outQueue, inQueue,
33+
configuration);
2534
}
2635

2736
@Test
2837
public void testChannelManagerIsCreated() {
29-
38+
3039
Mockito.verify(channelManagerFactory, Mockito.times(1)).create();
3140
}
41+
42+
@Test
43+
public void ifUserChoosesToPurgeRemoteDataThenMethodIsCalled()
44+
throws Exception {
45+
46+
Mockito.when(
47+
configuration.getProperty(
48+
Mockito.eq(Configuration.PURGE_REMOTE_ON_START),
49+
Mockito.eq("false"))).thenReturn("true");
50+
serverSync.start();
51+
Mockito.verify(channelManager, Mockito.times(1)).deleteRemoteData();
52+
}
53+
54+
@Test
55+
public void ifUserChoosesNotToPurgeRemoteDataThenMethodIsNotCalled()
56+
throws Exception {
57+
Mockito.when(
58+
configuration.getProperty(
59+
Mockito.eq(Configuration.PURGE_REMOTE_ON_START),
60+
Mockito.eq("false"))).thenReturn("false");
61+
serverSync.start();
62+
Mockito.verify(channelManager, Mockito.times(0)).deleteRemoteData();
63+
}
64+
65+
@Test
66+
public void ifNoChoiceIsMadeAboutPurgingRemoteDataThenMethodIsNotCalled()
67+
throws Exception {
68+
Mockito.when(
69+
configuration.getProperty(
70+
Mockito.eq(Configuration.PURGE_REMOTE_ON_START),
71+
Mockito.eq("false"))).thenReturn(null);
72+
serverSync.start();
73+
Mockito.verify(channelManager, Mockito.times(0)).deleteRemoteData();
74+
}
75+
3276
}

0 commit comments

Comments
 (0)