Skip to content
Permalink
Browse files
Added SystemPropertyAuthInit Test
Removed unused test method
corrected spelling mistake
  • Loading branch information
jhuynh1 committed Feb 14, 2020
1 parent 5b5d659 commit 7d7a77d715bf26365c8e3776302d498898b78391
Showing 5 changed files with 58 additions and 8 deletions.
@@ -54,13 +54,6 @@ protected GeodeConnectorConfig() {
taskId = 0;
}

// Just for testing
protected GeodeConnectorConfig(Map<String, String> props) {
super(new ConfigDef(), props);
taskId = 0;
}


public GeodeConnectorConfig(ConfigDef configDef, Map<String, String> connectorProperties) {
super(configDef, connectorProperties);
taskId = getInt(TASK_ID);
@@ -138,7 +138,7 @@ private Region createProxyRegion(String regionName) {
return geodeContext.getClientCache().createClientRegionFactory(ClientRegionShortcut.PROXY)
.create(regionName);
} catch (RegionExistsException e) {
// Each task is a seperate parallel task controlled by kafka.
// Each task is a separate parallel task controlled by kafka.
return geodeContext.getClientCache().getRegion(regionName);
}
}
@@ -0,0 +1,27 @@
package org.geode.kafka.security;

import org.apache.geode.security.AuthInitialize;
import org.junit.Test;

import java.util.Properties;

import static org.geode.kafka.GeodeConnectorConfig.SECURITY_PASSWORD;
import static org.geode.kafka.GeodeConnectorConfig.SECURITY_USER;
import static org.junit.Assert.assertEquals;

public class SystemPropertyAuthInitTest {

@Test
public void userNameAndPasswordAreObtainedFromSecurityProps() {
SystemPropertyAuthInit auth = new SystemPropertyAuthInit();
String userName = "someUsername";
String password = "somePassword";

Properties securityProps = new Properties();
securityProps.put(SECURITY_USER, userName);
securityProps.put(SECURITY_PASSWORD, password);
Properties credentials = auth.getCredentials(securityProps, null, true);
assertEquals(credentials.get((AuthInitialize.SECURITY_USERNAME)), userName);
assertEquals(credentials.get((AuthInitialize.SECURITY_PASSWORD)), password);
}
}
@@ -16,6 +16,7 @@

import static org.geode.kafka.sink.GeodeSinkConnectorConfig.NULL_VALUES_MEAN_REMOVE;
import static org.geode.kafka.sink.GeodeSinkConnectorConfig.TOPIC_TO_REGION_BINDINGS;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -69,4 +70,28 @@ public void putRecordsAddsToRegionBatchRecords() {
assertTrue(batchRecordsMap.containsKey("region"));
verify(batchRecords, times(1)).addUpdateOperation(topicRecord, nullMeansRemove);
}

@Test
public void newBatchRecordsAreCreatedIfOneDoesntExist() {
boolean nullMeansRemove = true;
GeodeKafkaSinkTask task = new GeodeKafkaSinkTask();
HashMap<String, String> props = createTestSinkProps(nullMeansRemove);

SinkRecord topicRecord = mock(SinkRecord.class);
when(topicRecord.topic()).thenReturn("topic");
when(topicRecord.value()).thenReturn("value");
when(topicRecord.key()).thenReturn("key");

List<SinkRecord> records = new ArrayList();
records.add(topicRecord);

HashMap<String, Region> regionNameToRegion = new HashMap<>();
GeodeSinkConnectorConfig geodeSinkConnectorConfig = new GeodeSinkConnectorConfig(props);
HashMap<String, BatchRecords> batchRecordsMap = new HashMap();
task.configure(geodeSinkConnectorConfig);
task.setRegionNameToRegion(regionNameToRegion);

task.put(records, batchRecordsMap);
assertNotNull(batchRecordsMap.get("region"));
}
}
@@ -28,6 +28,11 @@

public class GeodeKafkaSinkTest {

@Test
public void taskClassReferencesCorrectSinkTaskClass() {
assertEquals(GeodeKafkaSinkTask.class, new GeodeKafkaSink().taskClass());
}

@Test
public void taskConfigsCreatesMaxNumberOfTasks() {
GeodeKafkaSink sink = new GeodeKafkaSink();

0 comments on commit 7d7a77d

Please sign in to comment.