Search in sources :

Example 1 with NiFiProperties

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]);
        }
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContentClaim(org.apache.nifi.controller.repository.claim.ContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) StandardContentClaim(org.apache.nifi.controller.repository.claim.StandardContentClaim) ResourceClaim(org.apache.nifi.controller.repository.claim.ResourceClaim) Test(org.junit.Test)

Example 2 with NiFiProperties

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"));
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Test(org.junit.Test)

Example 3 with NiFiProperties

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);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties)

Example 4 with NiFiProperties

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();
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) File(java.io.File) Test(org.junit.Test)

Example 5 with NiFiProperties

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);
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) Bundle(org.apache.nifi.bundle.Bundle) Test(org.junit.Test)

Aggregations

NiFiProperties (org.apache.nifi.util.NiFiProperties)98 Test (org.junit.Test)63 HashMap (java.util.HashMap)28 Properties (java.util.Properties)24 File (java.io.File)16 Bundle (org.apache.nifi.bundle.Bundle)13 Matchers.anyString (org.mockito.Matchers.anyString)13 IOException (java.io.IOException)10 HashSet (java.util.HashSet)10 Map (java.util.Map)8 X509Certificate (java.security.cert.X509Certificate)7 Mockito.anyString (org.mockito.Mockito.anyString)7 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 SystemBundle (org.apache.nifi.nar.SystemBundle)6 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IdentityMapping (org.apache.nifi.authorization.util.IdentityMapping)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 FileInputStream (java.io.FileInputStream)4