@Override
    protected void close() {
        // Turn off consul heartbeat sending
        final Object registerWatch = RegisterContext.INSTANCE.getRegisterWatch();
        if ((registerWatch instanceof ConsulCatalogWatch) && canStopTask(registerWatch)) {
            ConsulCatalogWatch watch = (ConsulCatalogWatch) registerWatch;
            watch.stop();
            LOGGER.warning("Consul heartbeat has been closed.");
        } else {
            // The consul heartbeat is disabled by using a timer, which exists only in 1.x.x
            final Object scheduleProcessor = RegisterContext.INSTANCE.getScheduleProcessor();
            final Optional<Object> scheduledTasks = ReflectUtils.getFieldValue(scheduleProcessor, "scheduledTasks");
            if (!scheduledTasks.isPresent()) {
                return;
            }
            final Object tasks = scheduledTasks.get();
            if (tasks instanceof Map) {
                Map<Object, Set<ScheduledTask>> convertTasks = (Map<Object, Set<ScheduledTask>>) tasks;
                final Set<ScheduledTask> heartBeatTasks =
                        convertTasks.remove(RegisterContext.INSTANCE.getRegisterWatch());
                if (heartBeatTasks == null) {
                    return;
                }
                for (ScheduledTask scheduledTask : heartBeatTasks) {
                    scheduledTask.cancel();
                }
                LOGGER.warning("Consul heartbeat has been closed by stopping scheduled task.");
            }
        }
    }
@Test
    public void close() {
        final ConsulCatalogWatch watch = Mockito.mock(ConsulCatalogWatch.class);
        RegisterContext.INSTANCE.setRegisterWatch(watch);
        interceptor.close();
        Mockito.verify(watch, Mockito.times(1)).stop();
        final ScheduledAnnotationBeanPostProcessor processor = new ScheduledAnnotationBeanPostProcessor();
        final Optional<Object> scheduledTasks = ReflectUtils.getFieldValue(processor, "scheduledTasks");
        Assert.assertTrue(scheduledTasks.isPresent() && scheduledTasks.get() instanceof Map);
        Map<Object, Set<ScheduledTask>> tasks = (Map<Object, Set<ScheduledTask>>) scheduledTasks.get();
        final ScheduledTask task = Mockito.mock(ScheduledTask.class);
        RegisterContext.INSTANCE.setRegisterWatch(new Object());
        tasks.put(RegisterContext.INSTANCE.getRegisterWatch(), Collections.singleton(task));
        RegisterContext.INSTANCE.setScheduleProcessor(processor);
        interceptor.close();
        Mockito.verify(task, Mockito.times(1)).cancel();
        RegisterContext.INSTANCE.setScheduleProcessor(null);
        RegisterContext.INSTANCE.setRegisterWatch(null);
    }