JobNodeStorage { public void fillJobNodeIfNullOrOverwrite(final String node, final Object value) { if (!isJobNodeExisted(node) || (jobConfiguration.isOverwrite() && !value.toString().equals(getJobNodeDataDirectly(node)))) { coordinatorRegistryCenter.persist(jobNodePath.getFullPath(node), value.toString()); } } JobNodeStorage(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); boolean isJobNodeExisted(final String node); String getJobNodeData(final String node); String getJobNodeDataDirectly(final String node); List<String> getJobNodeChildrenKeys(final String node); void createJobNodeIfNeeded(final String node); void removeJobNodeIfExisted(final String node); void fillJobNodeIfNullOrOverwrite(final String node, final Object value); void fillEphemeralJobNode(final String node, final Object value); void updateJobNode(final String node, final Object value); void replaceJobNode(final String node, final Object value); void executeInTransaction(final TransactionExecutionCallback callback); void executeInLeader(final String latchNode, final LeaderExecutionCallback callback); void addConnectionStateListener(final ConnectionStateListener listener); void addDataListener(final TreeCacheListener listener); long getRegistryCenterTime();  }
@Test public void assertFillJobNodeIfNotNullAndOverwriteDisabled() { when(coordinatorRegistryCenter.isExisted("/testJob/config/cron")).thenReturn(true); jobNodeStorage.fillJobNodeIfNullOrOverwrite("config/cron", "0/1 * * * * ?"); verify(coordinatorRegistryCenter).isExisted("/testJob/config/cron"); verify(coordinatorRegistryCenter, times(0)).persist("/testJob/config/cron", "0/1 * * * * ?"); }
@Test public void assertFillJobNodeIfNotNullAndOverwriteEnabledButValueSame() { when(coordinatorRegistryCenter.isExisted("/testJob/config/cron")).thenReturn(true); when(coordinatorRegistryCenter.getDirectly("/testJob/config/cron")).thenReturn("0/1 * * * * ?"); jobConfig.setOverwrite(true); jobNodeStorage.fillJobNodeIfNullOrOverwrite("config/cron", "0/1 * * * * ?"); verify(coordinatorRegistryCenter).isExisted("/testJob/config/cron"); verify(coordinatorRegistryCenter).getDirectly("/testJob/config/cron"); verify(coordinatorRegistryCenter, times(0)).persist("/testJob/config", "0/1 * * * * ?"); }
@Test public void assertFillJobNodeIfNotNullAndOverwriteEnabledAndValueDifferent() { when(coordinatorRegistryCenter.isExisted("/testJob/config/cron")).thenReturn(true); when(coordinatorRegistryCenter.getDirectly("/testJob/config/cron")).thenReturn("0/1 * * * * ?"); jobConfig.setOverwrite(true); jobNodeStorage.fillJobNodeIfNullOrOverwrite("config/cron", "0/2 * * * * ?"); verify(coordinatorRegistryCenter).isExisted("/testJob/config/cron"); verify(coordinatorRegistryCenter).getDirectly("/testJob/config/cron"); verify(coordinatorRegistryCenter).persist("/testJob/config/cron", "0/2 * * * * ?"); }
@Test public void assertFillJobNodeIfNull() { when(coordinatorRegistryCenter.isExisted("/testJob/config/cron")).thenReturn(false); jobNodeStorage.fillJobNodeIfNullOrOverwrite("config/cron", "0/2 * * * * ?"); verify(coordinatorRegistryCenter).isExisted("/testJob/config/cron"); verify(coordinatorRegistryCenter).persist("/testJob/config/cron", "0/2 * * * * ?"); }