()
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void ctor() throws Exception { |
| 58 | HistogramCodecManager manager = |
| 59 | new HistogramCodecManager(tsdb); |
| 60 | assertEquals(0, manager.getCodec(SimpleHistogramDecoder.class)); |
| 61 | assertEquals(1, manager.getCodec(MockDecoder.class)); |
| 62 | HistogramDataPointCodec codec = manager.getCodec(0); |
| 63 | assertEquals(0, codec.getId()); |
| 64 | assertTrue(codec instanceof SimpleHistogramDecoder); |
| 65 | codec = manager.getCodec(1); |
| 66 | assertEquals(1, codec.getId()); |
| 67 | assertTrue(codec instanceof MockDecoder); |
| 68 | |
| 69 | // bad JSON |
| 70 | config.overrideConfig("tsd.core.histograms.config", |
| 71 | "{\"net.opentsdb.core.SimpleHistogramDecoder\": "); |
| 72 | try { |
| 73 | new HistogramCodecManager(tsdb); |
| 74 | fail("Expected IllegalArgumentException"); |
| 75 | } catch (IllegalArgumentException e) { } |
| 76 | |
| 77 | // id too small |
| 78 | config.overrideConfig("tsd.core.histograms.config", |
| 79 | "{\"net.opentsdb.core.SimpleHistogramDecoder\":-1}s"); |
| 80 | try { |
| 81 | new HistogramCodecManager(tsdb); |
| 82 | fail("Expected IllegalArgumentException"); |
| 83 | } catch (IllegalArgumentException e) { } |
| 84 | |
| 85 | // id too big |
| 86 | config.overrideConfig("tsd.core.histograms.config", |
| 87 | "{\"net.opentsdb.core.SimpleHistogramDecoder\":256}s"); |
| 88 | try { |
| 89 | new HistogramCodecManager(tsdb); |
| 90 | fail("Expected IllegalArgumentException"); |
| 91 | } catch (IllegalArgumentException e) { } |
| 92 | |
| 93 | // duplicate ID |
| 94 | config.overrideConfig("tsd.core.histograms.config", |
| 95 | "{\"net.opentsdb.core.SimpleHistogramDecoder\": 42," |
| 96 | + "\"net.opentsdb.core.TestHistogramCodecManager$MockDecoder\":42}"); |
| 97 | try { |
| 98 | new HistogramCodecManager(tsdb); |
| 99 | fail("Expected IllegalArgumentException"); |
| 100 | } catch (IllegalArgumentException e) { } |
| 101 | |
| 102 | config.overrideConfig("tsd.core.histograms.config", "nosuchfile.json"); |
| 103 | when(Files.toString(any(File.class), eq(Const.UTF8_CHARSET))) |
| 104 | .thenReturn("{\"net.opentsdb.core.SimpleHistogramDecoder\": 0}"); |
| 105 | manager = new HistogramCodecManager(tsdb); |
| 106 | assertEquals(0, manager.getCodec(SimpleHistogramDecoder.class)); |
| 107 | assertTrue(manager.getCodec(0) instanceof SimpleHistogramDecoder); |
| 108 | |
| 109 | when(Files.toString(any(File.class), eq(Const.UTF8_CHARSET))) |
| 110 | .thenThrow(new IOException("Boo!")); |
| 111 | try { |
| 112 | new HistogramCodecManager(tsdb); |
| 113 | fail("Expected RuntimeException"); |
nothing calls this directly
no test coverage detected