1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.neo4j.server.configuration;
21
22 import static org.hamcrest.Matchers.containsString;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.File;
28 import java.io.IOException;
29
30 import org.junit.Test;
31 import org.neo4j.server.logging.InMemoryAppender;
32
33
34 public class PropertyFileConfiguratorTest {
35 @Test
36 public void whenDatabaseTuningFilePresentInDefaultLocationShouldLoadItEvenIfNotSpecified() throws IOException {
37 File emptyPropertyFile = PropertyFileBuilder.builder().build();
38 DatabaseTuningPropertyFileBuilder.builder().inDirectory(emptyPropertyFile.getParentFile()).build();
39
40 PropertyFileConfigurator configurator = new PropertyFileConfigurator(emptyPropertyFile);
41
42 assertNotNull(configurator.getDatabaseTuningProperties().get("neostore.nodestore.db.mapped_memory"));
43 assertEquals("25M", configurator.getDatabaseTuningProperties().get("neostore.nodestore.db.mapped_memory"));
44 }
45
46 @Test
47 public void whenDatabaseTuningFilePresentInDefaultLocationShouldNotLoadIfAnotherSpecified() throws IOException {
48 int unlikelyDefaultMemoryMappedValue = 8351;
49 File databaseTuningPropertyFileWeWantToUse = DatabaseTuningPropertyFileBuilder.builder().mappedMemory(unlikelyDefaultMemoryMappedValue).build();
50 File emptyPropertyFile = PropertyFileBuilder.builder().withDbTuningPropertyFile(databaseTuningPropertyFileWeWantToUse).build();
51
52 DatabaseTuningPropertyFileBuilder.builder().inDirectory(emptyPropertyFile.getParentFile()).build();
53
54 PropertyFileConfigurator configurator = new PropertyFileConfigurator(emptyPropertyFile);
55
56 assertNotNull(configurator.getDatabaseTuningProperties().get("neostore.nodestore.db.mapped_memory"));
57 assertEquals(String.valueOf(unlikelyDefaultMemoryMappedValue) + "M", configurator.getDatabaseTuningProperties().get("neostore.nodestore.db.mapped_memory"));
58 }
59
60 @Test
61 public void shouldLogInfoWhenDefaultingToTuningPropertiesFileInTheSameDirectoryAsTheNeoServerPropertiesFile() throws IOException {
62 File emptyPropertyFile = PropertyFileBuilder.builder().build();
63 File tuningPropertiesFile = DatabaseTuningPropertyFileBuilder.builder().inDirectory(emptyPropertyFile.getParentFile()).build();
64
65 InMemoryAppender appender = new InMemoryAppender(PropertyFileConfigurator.log);
66 PropertyFileConfigurator configurator = new PropertyFileConfigurator(emptyPropertyFile);
67
68 assertThat(appender.toString(), containsString(String.format("INFO - No database tuning file explicitly set, defaulting to [%s]",tuningPropertiesFile.getAbsolutePath())));
69 }
70 }