RequestRateConfiguration { public static RequestRateConfiguration create(Map<String, Object> options) throws ConfigurationException { RequestRateConfiguration conf = new RequestRateConfiguration(); Yaml yaml = new Yaml(); String str = yaml.dumpAsMap(options); try { conf.values = yaml.loadAs(str, RequestRateConfiguration.Values.class); } catch (Exception e) { throw new ConfigurationException("Unable to load configuration.", e); } validateRequestsToReport(conf); return conf; } private  RequestRateConfiguration(); static RequestRateConfiguration create(Map<String, Object> options); int period(); TimeUnit timeunit(); long reportingRateInMillis(); List<String> requestsToReport(); static final String ALL_STATEMENT_TYPES; static final String ALL_CONSISTENCY_LEVELS; static final String REQUEST_META_DELIMITER; }
@Test public void fails_when_incorrect_values_provided() { Map<String, Object> options = new HashMap<>(); options.put("period", 2); options.put("timeunit", "ERR"); try { RequestRateConfiguration.create(options); } catch (Exception e) { assertThat(e).isInstanceOf(ConfigurationException.class); } }
@Test public void fails_when_incorrect_requests_to_report() { Map<String, Object> options = new HashMap<>(); options.put("requestsToReport", Arrays.asList("SOMETHING")); try { RequestRateConfiguration.create(options); } catch (Exception e) { assertThat(e).isInstanceOf(ConfigurationException.class) .hasMessage("Only two configuration parameters supported, statement type and consistency level."); } }
@Test public void fails_when_incorrect_statement_type() { Map<String, Object> options = new HashMap<>(); options.put("requestsToReport", Arrays.asList("SOMETHING:LOCAL_ONE")); try { RequestRateConfiguration.create(options); } catch (Exception e) { assertThat(e).isInstanceOf(ConfigurationException.class) .hasMessage("Illegal statement type configured: SOMETHING"); } }
@Test public void fails_when_incorrect_consistency_level() { Map<String, Object> options = new HashMap<>(); options.put("requestsToReport", Arrays.asList("SELECT:SOMETHING")); try { RequestRateConfiguration.create(options); } catch (Exception e) { assertThat(e).isInstanceOf(ConfigurationException.class) .hasMessage("Illegal consistency level configured: SOMETHING"); } }