Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the reloadRules method that caused ruleMetaData.getRules() to be null briefly #26007

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hua74ni
Copy link
Contributor

@hua74ni hua74ni commented Jun 2, 2023

Changes proposed in this pull request:

  • Fixed the reloadRules method that caused ruleMetaData.getRules() to be null briefly

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

@hua74ni
Copy link
Contributor Author

hua74ni commented Jun 2, 2023

Test cases

@Test
public void assertTest() throws InterruptedException {

    ShardingSphereRuleMetaData ruleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(new ShardingSphereRuleFixture()));

    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            System.out.println("start cycle get ruleMetaData rules...");
            while (true) {
                if (CollectionUtils.isEmpty(ruleMetaData.getRules())) {
                    System.out.println("ruleMetaData rules is null!!!!");
                }
            }
        }
    });
    thread.setDaemon(true);
    thread.start();

    Thread.sleep(1000);

    boolean flag = false;
    System.out.println("start replace all ruleMetaData rules...");
    if (flag) {
        ((CopyOnWriteArrayList) ruleMetaData.getRules()).replaceAll(shardingSphereRule -> {
            return new ShardingSphereRuleFixture();
        });
    } else {
        ShardingSphereRuleMetaData newRuleMetaData = new ShardingSphereRuleMetaData(Collections.singleton(new ShardingSphereRuleFixture()));
        ruleMetaData.getRules().clear();
        ruleMetaData.getRules().addAll(newRuleMetaData.getRules());
    }

    System.out.println("finished replace all ruleMetaData rules...");

    Thread.sleep(3000);
}

@hua74ni
Copy link
Contributor Author

hua74ni commented Jun 12, 2023

@zhaojinchao95 Help review or make suggestions

@github-actions github-actions bot added the stale label Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant