• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

Hyshmily / hotkey / 28735434673

05 Jul 2026 08:55AM UTC coverage: 90.421% (+0.02%) from 90.4%
28735434673

push

github

Hyshmily
perf : simplify the code

Signed-off-by: Hyshmily <cxm8607@outlook.com>

1295 of 1498 branches covered (86.45%)

Branch coverage included in aggregate %.

121 of 134 new or added lines in 11 files covered. (90.3%)

2 existing lines in 1 file now uncovered.

3689 of 4014 relevant lines covered (91.9%)

4.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/common/src/main/java/io/github/hyshmily/hotkey/endpoint/RingEndpoint.java
1
/*
2
 * Copyright 2026 Hyshmily. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package io.github.hyshmily.hotkey.endpoint;
17

18
import io.github.hyshmily.hotkey.Internal;
19
import io.github.hyshmily.hotkey.sharding.ClusterHealthView;
20
import io.github.hyshmily.hotkey.sharding.RingManager;
21
import java.util.LinkedHashMap;
22
import java.util.Map;
23
import org.jspecify.annotations.Nullable;
24
import org.springframework.beans.factory.ObjectProvider;
25
import org.springframework.util.Assert;
26
import org.springframework.web.bind.annotation.GetMapping;
27
import org.springframework.web.bind.annotation.PathVariable;
28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RestController;
30

31
/**
32
 * Actuator {@code /actuator/hotkeyring} endpoint for consistent-hash ring inspection.
33
 *
34
 * <p>Operations:
35
 * <ul>
36
 *   <li>{@code GET /actuator/hotkeyring} — ring topology
37
 *   <li>{@code GET /actuator/hotkeyring/{key}} — query which node handles a key
38
 * </ul>
39
 */
40
@Internal
41
@RestController
42
@RequestMapping("${management.endpoints.web.base-path:/actuator}/hotkeyring")
43
public class RingEndpoint {
44

45
  @Nullable
46
  private final RingManager ringManager;
47

48
  private final ObjectProvider<ClusterHealthView> healthViewProvider;
49

50
  public RingEndpoint(@Nullable RingManager ringManager, ObjectProvider<ClusterHealthView> healthViewProvider) {
2✔
51
    this.ringManager = ringManager;
3✔
52
    this.healthViewProvider = healthViewProvider;
3✔
53
  }
1✔
54

55
  /**
56
   * Return the current ring topology: node count, virtual node count,
57
   * and the sorted list of live nodes.
58
   *
59
   * @return a map containing {@code nodeCount}, {@code virtualNodes},
60
   *         and {@code nodes} entries
61
   */
62
  @GetMapping
63
  public Map<String, Object> ringInfo() {
64
    if (ringManager == null) {
3!
NEW
65
      return Map.of("error", "RingManager not available (RabbitMQ absent)");
×
66
    }
67
    Map<String, Object> result = new LinkedHashMap<>();
4✔
68
    result.put("nodeCount", ringManager.nodeCount());
8✔
69
    result.put("virtualNodes", ringManager.getVirtualNodeCount());
8✔
70
    result.put("nodes", ringManager.getCurrentNodes().stream().sorted().toList());
10✔
71
    return result;
2✔
72
  }
73

74
  /**
75
   * Determine which node is responsible for the given key.
76
   * <p>When the cluster health view is unavailable (e.g. no Workers have
77
   * ever connected), a fallback view with zero expected nodes is used,
78
   * which may route the key to a local placeholder.</p>
79
   *
80
   * @param key the cache key to look up; must not be empty
81
   * @return a map containing the key and its assigned node ID
82
   * @throws IllegalArgumentException if {@code key} is empty
83
   */
84
  @GetMapping("/{key}")
85
  public Map<String, Object> keyMapping(@PathVariable String key) {
86
    Assert.hasText(key, "key must not be empty");
3✔
87
    if (ringManager == null) {
3!
NEW
88
      return Map.of("error", "RingManager not available (RabbitMQ absent)");
×
89
    }
90
    Map<String, Object> result = new LinkedHashMap<>();
4✔
91
    result.put("key", key);
5✔
92
    ClusterHealthView view = healthViewProvider.getIfAvailable();
5✔
93
    if (view == null) {
2✔
94
      view = new ClusterHealthView(0, 0, 0);
7✔
95
    }
96
    result.put("nodeId", ringManager.routeNode(key, view));
9✔
97
    return result;
2✔
98
  }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc