use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestVolatileContentRepository method testRedirects.
@Test
public void testRedirects() throws IOException {
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestVolatileContentRepository.class.getResource("/conf/nifi.properties").getFile());
final Map<String, String> addProps = new HashMap<>();
addProps.put(VolatileContentRepository.MAX_SIZE_PROPERTY, "10 MB");
final NiFiProperties nifiProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
final VolatileContentRepository contentRepo = new VolatileContentRepository(nifiProps);
contentRepo.initialize(claimManager);
final ContentClaim claim = contentRepo.create(true);
final OutputStream out = contentRepo.write(claim);
final byte[] oneK = new byte[1024];
Arrays.fill(oneK, (byte) 55);
// Write 10 MB to the repo
for (int i = 0; i < 10240; i++) {
out.write(oneK);
}
try {
out.write(1);
Assert.fail("Expected to be out of space on content repo");
} catch (final IOException e) {
}
try {
out.write(1);
Assert.fail("Expected to be out of space on content repo");
} catch (final IOException e) {
}
final ContentRepository mockRepo = Mockito.mock(ContentRepository.class);
contentRepo.setBackupRepository(mockRepo);
final ResourceClaim resourceClaim = claimManager.newResourceClaim("container", "section", "1000", true, false);
final ContentClaim contentClaim = new StandardContentClaim(resourceClaim, 0L);
Mockito.when(mockRepo.create(Matchers.anyBoolean())).thenReturn(contentClaim);
final ByteArrayOutputStream overflowStream = new ByteArrayOutputStream();
Mockito.when(mockRepo.write(Matchers.any(ContentClaim.class))).thenReturn(overflowStream);
out.write(10);
assertEquals(1024 * 1024 * 10 + 1, overflowStream.size());
final byte[] overflowBuffer = overflowStream.toByteArray();
assertEquals(55, overflowBuffer[0]);
for (int i = 0; i < overflowBuffer.length; i++) {
if (i == overflowBuffer.length - 1) {
assertEquals(10, overflowBuffer[i]);
} else {
assertEquals(55, overflowBuffer[i]);
}
}
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestFlowConfigurationArchiveManager method testNiFiPropertiesMaxStorage.
@Test
public void testNiFiPropertiesMaxStorage() throws Exception {
final NiFiProperties withMaxTime = mock(NiFiProperties.class);
when(withMaxTime.getFlowConfigurationArchiveMaxCount()).thenReturn(null);
when(withMaxTime.getFlowConfigurationArchiveMaxTime()).thenReturn(null);
when(withMaxTime.getFlowConfigurationArchiveMaxStorage()).thenReturn("10 MB");
final FlowConfigurationArchiveManager archiveManager = new FlowConfigurationArchiveManager(flowFile.toPath(), withMaxTime);
assertNull(getPrivateFieldValue(archiveManager, "maxCount"));
assertNull(getPrivateFieldValue(archiveManager, "maxTimeMillis"));
assertEquals(10L * 1024L * 1024L, getPrivateFieldValue(archiveManager, "maxStorageBytes"));
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestFlowConfigurationArchiveManager method createArchiveManager.
private FlowConfigurationArchiveManager createArchiveManager(final Integer maxCount, final String maxTime, final String maxStorage) {
final NiFiProperties properties = mock(NiFiProperties.class);
when(properties.getFlowConfigurationArchiveDir()).thenReturn(archiveDir.getPath());
when(properties.getFlowConfigurationArchiveMaxCount()).thenReturn(maxCount);
when(properties.getFlowConfigurationArchiveMaxTime()).thenReturn(maxTime);
when(properties.getFlowConfigurationArchiveMaxStorage()).thenReturn(maxStorage);
return new FlowConfigurationArchiveManager(flowFile.toPath(), properties);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestFlowConfigurationArchiveManager method testArchiveWithoutOriginalFile.
@Test(expected = NoSuchFileException.class)
public void testArchiveWithoutOriginalFile() throws Exception {
final NiFiProperties properties = mock(NiFiProperties.class);
when(properties.getFlowConfigurationArchiveDir()).thenReturn(archiveDir.getPath());
final File flowFile = new File("does-not-exist");
final FlowConfigurationArchiveManager archiveManager = new FlowConfigurationArchiveManager(flowFile.toPath(), properties);
archiveManager.archive();
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class NarThreadContextClassLoaderTest method validateWithPropertiesConstructor.
@Test
public void validateWithPropertiesConstructor() throws Exception {
NiFiProperties properties = NiFiProperties.createBasicNiFiProperties("src/test/resources/nifi.properties", null);
Bundle systemBundle = SystemBundle.create(properties);
ExtensionManager.discoverExtensions(systemBundle, Collections.emptySet());
Object obj = NarThreadContextClassLoader.createInstance(WithPropertiesConstructor.class.getName(), WithPropertiesConstructor.class, properties);
assertTrue(obj instanceof WithPropertiesConstructor);
WithPropertiesConstructor withPropertiesConstructor = (WithPropertiesConstructor) obj;
assertNotNull(withPropertiesConstructor.properties);
}
Aggregations