ShardingSphereAlgorithmFactory { @SuppressWarnings("unchecked") public static <T extends ShardingSphereAlgorithm> T createAlgorithm(final TypedSPIConfiguration typedSPIConfig, final Class<? extends ShardingSphereAlgorithm> algorithmClass) { T result = (T) TypedSPIRegistry.getRegisteredService(algorithmClass, typedSPIConfig.getType(), typedSPIConfig.getProps()); if (result instanceof ShardingSphereAlgorithmPostProcessor) { ((ShardingSphereAlgorithmPostProcessor) result).init(); } return result; }  @SuppressWarnings("unchecked") static T createAlgorithm(final TypedSPIConfiguration typedSPIConfig, final Class<? extends ShardingSphereAlgorithm> algorithmClass);  }
@Test public void assertCreateAlgorithmWithoutInit() { Properties props = new Properties(); props.setProperty("key", "value"); ShardingSphereAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(new ShardingSphereAlgorithmConfiguration("WITHOUT_INIT", props), ShardingSphereAlgorithm.class); assertThat(actual, instanceOf(WithoutInitAlgorithm.class)); assertThat(actual.getProps().getProperty("key"), is("value")); }
@Test public void assertCreateAlgorithmWithInit() { Properties props = new Properties(); props.setProperty("key", "value"); ShardingSphereAlgorithm actual = ShardingSphereAlgorithmFactory.createAlgorithm(new ShardingSphereAlgorithmConfiguration("WITH_INIT", props), ShardingSphereAlgorithm.class); assertThat(actual, instanceOf(WithInitAlgorithm.class)); assertThat(actual.getProps().getProperty("key"), is("value")); assertThat(((WithInitAlgorithm) actual).getTestValue(), is("value")); }