You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/05/15 03:51:01 UTC

[GitHub] [shardingsphere] hitnewbee commented on a change in pull request #5616: Issue 5428 for SchemaChangedListenerTest.java

hitnewbee commented on a change in pull request #5616:
URL: https://github.com/apache/shardingsphere/pull/5616#discussion_r425551258



##########
File path: sharding-orchestration/sharding-orchestration-core/sharding-orchestration-core-configcenter/src/test/java/org/apache/shardingsphere/orchestration/core/configcenter/listener/SchemaChangedListenerTest.java
##########
@@ -120,16 +83,33 @@ public void assertCreateIgnoredEvent() {
     }
     
     @Test
-    public void assertCreateDataSourceChangedEventForExistedSchema() {
-        DataChangedEvent dataChangedEvent = new DataChangedEvent("/test/config/schema/sharding_db/datasource", DATA_SOURCE_YAML, ChangedType.UPDATED);
+    public void assertCreateDataSourceChangedEventForExistedSchema() throws IOException {
+        String dataSource = readYamlIntoString(DATA_SOURCE_YAML);
+        DataChangedEvent dataChangedEvent = new DataChangedEvent("/test/config/schema/sharding_db/datasource", dataSource, ChangedType.UPDATED);
         ShardingOrchestrationEvent actual = schemaChangedListener.createShardingOrchestrationEvent(dataChangedEvent);
         assertThat(actual, instanceOf(DataSourceChangedEvent.class));
         assertThat(((DataSourceChangedEvent) actual).getShardingSchemaName(), is("sharding_db"));
     }
+
+    private String readYamlIntoString(final String yamlFile) throws IOException {
+        File file = new File(Preconditions.checkNotNull(getClass().getClassLoader().getResource(yamlFile), "file resource `%s` must not be null.", yamlFile).getFile());
+        StringBuilder yamlContent = new StringBuilder();
+        FileReader fileReader = new FileReader(file);
+        BufferedReader reader = new BufferedReader(fileReader);
+        String line;
+        while (null != (line = reader.readLine())) {

Review comment:
       OK, I will try snake yaml




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org