use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class TestDbusKeyCompositeFilter method testDbusKeyRangeFilterErrors.
@Test
public void testDbusKeyRangeFilterErrors() throws Exception {
boolean isException = false;
//Error Case: Range Size is negative
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("RANGE");
KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
rangeConf.setSize(-1);
rangeConf.setPartitions("[0,3-4]");
partConf.setRange(rangeConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ice) {
isException = true;
}
assertEquals("Got Exception for invalid Config (Range Size is negative) ", true, isException);
isException = false;
//Error Case: min is greater than max
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("RANGE");
KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
rangeConf.setSize(100);
rangeConf.setPartitions("[0,5-4]");
partConf.setRange(rangeConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ice) {
isException = true;
}
assertEquals("Got Exception for invalid Config (min is greater than max) ", true, isException);
isException = false;
//Error Case: min is -ve
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("RANGE");
KeyRangeFilterConfig.Config rangeConf = new KeyRangeFilterConfig.Config();
rangeConf.setSize(100);
rangeConf.setPartitions("[-3,2-4]");
partConf.setRange(rangeConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ice) {
isException = true;
}
assertEquals("Got Exception for invalid Config (min is greater than max) ", true, isException);
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class TestDbusKeyCompositeFilter method testDbusKeyModFilterErrors.
@Test
public void testDbusKeyModFilterErrors() throws Exception {
//Error Config : MaxBucket is more than numBuckets
boolean isException = false;
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("MOD");
KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
modConf.setNumBuckets(5);
//invalid config
modConf.setBuckets("[0,3-9]");
partConf.setMod(modConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ie) {
ie.printStackTrace();
isException = true;
}
assertEquals("Got Exception for invalid Config (MaxBucket is more than numBuckets) ", true, isException);
//Error Case : Min Bucket is more than maxBucket
isException = false;
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("MOD");
KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
modConf.setNumBuckets(50);
//invalid config
modConf.setBuckets("[0,9-3]");
partConf.setMod(modConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ie) {
ie.printStackTrace();
isException = true;
}
assertEquals("Got Exception for invalid Config (Min Bucket is more than maxBucket) ", true, isException);
//Error Case : numBuckets is negative
isException = false;
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("MOD");
KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
modConf.setNumBuckets(-5);
//invalid config
modConf.setBuckets("[0]");
partConf.setMod(modConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ie) {
ie.printStackTrace();
isException = true;
}
assertEquals("Got Exception for invalid Config numBuckets is negative) ", true, isException);
//Error Case : minBucket is negative
isException = false;
try {
KeyFilterConfigHolder.Config partConf = new KeyFilterConfigHolder.Config();
partConf.setType("MOD");
KeyModFilterConfig.Config modConf = new KeyModFilterConfig.Config();
modConf.setNumBuckets(50);
//invalid config
modConf.setBuckets("[-5,1-3]");
partConf.setMod(modConf);
DbusKeyFilter filter = new DbusKeyFilter(new KeyFilterConfigHolder(partConf.build()));
} catch (InvalidConfigException ie) {
ie.printStackTrace();
isException = true;
}
assertEquals("Got Exception for invalid Config (minBucket is negative) ", true, isException);
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class SchemaRegistryConfigBuilder method build.
@Override
public SchemaRegistryStaticConfig build() throws InvalidConfigException {
RegistryType registryType = null;
try {
registryType = RegistryType.valueOf(_type);
} catch (Exception e) {
throw new InvalidConfigException("invalid schema registry type: " + _type);
}
_fileSystem.setEnabled(SchemaRegistryStaticConfig.RegistryType.FILE_SYSTEM == registryType);
// TODO Add config verification
return new SchemaRegistryStaticConfig(registryType, getFileSystem().build(), getExistingService());
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class OpenReplicatorEventProducerServiceProvider method buildPartitionFunction.
public PartitionFunction buildPartitionFunction(LogicalSourceStaticConfig sourceConfig) throws InvalidConfigException {
String partitionFunction = sourceConfig.getPartitionFunction();
if (partitionFunction.startsWith("constant:")) {
try {
String numberPart = partitionFunction.substring("constant:".length()).trim();
short constantPartitionNumber = Short.valueOf(numberPart);
return new ConstantPartitionFunction(constantPartitionNumber);
} catch (Exception ex) {
// Could be a NumberFormatException, IndexOutOfBoundsException or other exception when trying to parse the partition number.
throw new InvalidConfigException("Invalid partition configuration (" + partitionFunction + "). " + "Could not parse the constant partition number.");
}
} else {
throw new InvalidConfigException("Invalid partition configuration (" + partitionFunction + ").");
}
}
use of com.linkedin.databus.core.util.InvalidConfigException in project databus by linkedin.
the class OpenReplicatorEventProducerServiceProvider method buildEventFactory.
public OpenReplicatorAvroEventFactory buildEventFactory(LogicalSourceStaticConfig sourceConfig, PhysicalSourceStaticConfig pConfig, SchemaRegistryService schemaRegistryService) throws DatabusException, EventCreationException, UnsupportedKeyException, InvalidConfigException {
String schema = null;
try {
schema = schemaRegistryService.fetchLatestSchemaBySourceName(sourceConfig.getName());
} catch (NoSuchSchemaException e) {
throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
}
if (schema == null) {
throw new InvalidConfigException("Unable to load the schema for source (" + sourceConfig.getName() + ").");
}
LOG.info("Loading schema for source id " + sourceConfig.getId() + ": " + schema);
String eventViewSchema;
String eventView;
if (sourceConfig.getUri().indexOf('.') != -1) {
String[] parts = sourceConfig.getUri().split("\\.");
eventViewSchema = parts[0];
eventView = parts[1];
} else {
eventViewSchema = null;
eventView = sourceConfig.getUri();
}
PartitionFunction partitionFunction = buildPartitionFunction(sourceConfig);
OpenReplicatorAvroEventFactory factory = createEventFactory(eventViewSchema, eventView, sourceConfig, pConfig, schema, partitionFunction);
return factory;
}
Aggregations