use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithKeystorePasswordAndKeyPassword.
@Test
public void testConfigureSslContextFactoryWithKeystorePasswordAndKeyPassword() {
// Expect that if we set both passwords, KeyStore password is used for KeyStore, Key password is used for Key Manager
String testKeystorePassword = "testKeystorePassword";
String testKeyPassword = "testKeyPassword";
final Map<String, String> addProps = new HashMap<>();
addProps.put(NiFiProperties.SECURITY_KEYSTORE_PASSWD, testKeystorePassword);
addProps.put(NiFiProperties.SECURITY_KEY_PASSWD, testKeyPassword);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setKeyStorePassword(testKeystorePassword);
verify(contextFactory).setKeyManagerPassword(testKeyPassword);
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithKeyPassword.
@Test
public void testConfigureSslContextFactoryWithKeyPassword() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
// Expect that with no KeyStore password, we will only need to set Key Manager Password
String testKeyPassword = "testKeyPassword";
final Map<String, String> addProps = new HashMap<>();
addProps.put(NiFiProperties.SECURITY_KEY_PASSWD, testKeyPassword);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setKeyManagerPassword(testKeyPassword);
verify(contextFactory, never()).setKeyStorePassword(anyString());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class JettyServerTest method testConfigureSslContextFactoryWithJksKeyStore.
@Test
public void testConfigureSslContextFactoryWithJksKeyStore() {
// Expect that we will not set provider for jks keystore
final Map<String, String> addProps = new HashMap<>();
String keyStoreType = KeystoreType.JKS.toString();
addProps.put(NiFiProperties.SECURITY_KEYSTORE_TYPE, keyStoreType);
NiFiProperties nifiProperties = NiFiProperties.createBasicNiFiProperties(null, addProps);
SslContextFactory contextFactory = mock(SslContextFactory.class);
JettyServer.configureSslContextFactory(contextFactory, nifiProperties);
verify(contextFactory).setKeyStoreType(keyStoreType);
verify(contextFactory, never()).setKeyStoreProvider(anyString());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestVolatileContentRepository method testSimpleReadWrite.
@Test
public void testSimpleReadWrite() 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, "11 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 int byteCount = 2398473 * 4;
final byte[] x = new byte[4];
x[0] = 48;
x[1] = 29;
x[2] = 49;
x[3] = 51;
for (int i = 0; i < byteCount / 4; i++) {
out.write(x);
}
out.close();
final InputStream in = contentRepo.read(claim);
for (int i = 0; i < byteCount; i++) {
final int val = in.read();
final int index = i % 4;
final byte expectedVal = x[index];
assertEquals(expectedVal, val);
}
assertEquals(-1, in.read());
}
use of org.apache.nifi.util.NiFiProperties in project nifi by apache.
the class TestVolatileContentRepository method testMemoryIsFreed.
@Test
public void testMemoryIsFreed() throws IOException, InterruptedException {
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, "11 MB");
final NiFiProperties nifiProps = NiFiProperties.createBasicNiFiProperties(null, addProps);
final VolatileContentRepository contentRepo = new VolatileContentRepository(nifiProps);
contentRepo.initialize(claimManager);
final byte[] oneK = new byte[1024];
Arrays.fill(oneK, (byte) 55);
final ExecutorService exec = Executors.newFixedThreadPool(10);
for (int t = 0; t < 10; t++) {
final Runnable r = new Runnable() {
@Override
public void run() {
try {
for (int j = 0; j < 10000; j++) {
final ContentClaim claim = contentRepo.create(true);
final OutputStream out = contentRepo.write(claim);
// Write 1 MB to the repo
for (int i = 0; i < 1024; i++) {
out.write(oneK);
}
final int count = contentRepo.decrementClaimantCount(claim);
if (count <= 0) {
contentRepo.remove(claim);
}
}
} catch (final Exception e) {
e.printStackTrace();
}
}
};
exec.submit(r);
}
exec.shutdown();
exec.awaitTermination(100000, TimeUnit.MINUTES);
}
Aggregations