View Javadoc

1   package org.apache.helix.alerts;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.helix.HelixException;
23  import org.apache.helix.alerts.ExpressionParser;
24  import org.testng.annotations.Test;
25  import org.testng.AssertJUnit;
26  import org.testng.Assert;
27  import org.testng.annotations.Test;
28  
29  
30  @Test
31  public class TestStatsMatch {
32  
33  	@Test
34  	  public void testExactMatch()
35  	  {
36  	    
37  	    String persistedStatName = "window(5)(dbFoo.partition10.latency)";
38  	    String incomingStatName = "dbFoo.partition10.latency";
39  	    AssertJUnit.assertTrue(ExpressionParser.isIncomingStatExactMatch(persistedStatName, incomingStatName));
40  	  }
41  	
42  	@Test
43  	  public void testSingleWildcardMatch()
44  	  {
45  	    
46  	    String persistedStatName = "window(5)(dbFoo.partition*.latency)";
47  	    String incomingStatName = "dbFoo.partition10.latency";
48  	    AssertJUnit.assertTrue(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName));
49  	  }
50  	
51  	@Test
52  	  public void testDoubleWildcardMatch()
53  	  {
54  	    
55  	    String persistedStatName = "window(5)(db*.partition*.latency)";
56  	    String incomingStatName = "dbFoo.partition10.latency";
57  	    AssertJUnit.assertTrue(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName));
58  	  }
59  	
60  	@Test
61  	  public void testWildcardMatchNoWildcard()
62  	  {
63  	    
64  	    String persistedStatName = "window(5)(dbFoo.partition10.latency)";
65  	    String incomingStatName = "dbFoo.partition10.latency";
66  	    AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName));
67  	  }
68  	
69  	@Test
70  	  public void testWildcardMatchTooManyFields()
71  	  {
72  	    
73  	    String persistedStatName = "window(5)(dbFoo.partition*.latency)";
74  	    String incomingStatName = "dbFoo.tableBar.partition10.latency";
75  	    AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName));
76  	  }
77  	
78  	@Test
79  	  public void testWildcardMatchTooFewFields()
80  	  {
81  	    
82  	    String persistedStatName = "window(5)(dbFoo.partition*.latency)";
83  	    String incomingStatName = "dbFoo.latency";
84  	    AssertJUnit.assertFalse(ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName));
85  	  }
86  	
87  
88  	@Test
89  	  public void testBadWildcardRepeated()
90  	  {
91  	    
92  	    String persistedStatName = "window(5)(dbFoo.partition**4.latency)";
93  	    String incomingStatName = "dbFoo.partition10.latency";
94  	    boolean match = ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName);
95  	    
96  	    AssertJUnit.assertFalse(match);
97  	  }
98  	
99  	@Test
100 	  public void testBadWildcardNotAtEnd()
101 	  {
102 	    
103 	    String persistedStatName = "window(5)(dbFoo.*partition.latency)";
104 	    String incomingStatName = "dbFoo.partition10.latency";
105 	    boolean match = ExpressionParser.isIncomingStatWildcardMatch(persistedStatName, incomingStatName);
106 	    
107 	    AssertJUnit.assertFalse(match);
108 	  }
109 }