@Override
    public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) {
        // Create the configuration and validate it.
        C config = createConfig(subject, configClass, json);

        try {
            checkArgument(config.isValid(), INVALID_CONFIG_JSON);
        } catch (RuntimeException e) {
            ConfigFactory<S, C> configFactory = getConfigFactory(configClass);
            String subjectKey = configFactory.subjectFactory().subjectClassKey();
            String subjectString = configFactory.subjectFactory().subjectKey(config.subject());
            String configKey = config.key();

            throw new InvalidConfigException(subjectKey, subjectString, configKey, e);
        }

        // Insert the validated configuration and get it back.
        Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json);

        // Re-create the config if for some reason what we attempted to put
        // was supplanted by someone else already.
        return versioned.value() == json ? config : createConfig(subject, configClass, versioned.value());
    }
@Test
    public void testApplyConfig() {
        configStore.addConfigFactory(new MockConfigFactory(BasicConfig.class, "config1"));

        configStore.applyConfig("subject", BasicConfig.class, new ObjectMapper().createObjectNode());
        assertThat(configStore.getConfigClasses("subject"), hasSize(1));
        assertThat(configStore.getSubjects(String.class, BasicConfig.class), hasSize(1));
        assertThat(configStore.getSubjects(String.class), hasSize(1));
    }