|
| 1 | +package org.hypertrace.partitioner.config.service; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import java.util.List; |
| 6 | +import org.hypertrace.partitioner.config.service.v1.PartitionerGroup; |
| 7 | +import org.hypertrace.partitioner.config.service.v1.PartitionerProfile; |
| 8 | +import org.hypertrace.partitioner.config.service.v1.PutPartitionerProfilesRequest; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | + |
| 11 | +class PartitionerConfigServiceRequestValidatorTest { |
| 12 | + |
| 13 | + @Test |
| 14 | + public void testProfileNameExists() { |
| 15 | + PartitionerConfigServiceRequestValidator underTest = |
| 16 | + new PartitionerConfigServiceRequestValidator(); |
| 17 | + |
| 18 | + Exception exception = |
| 19 | + assertThrows( |
| 20 | + RuntimeException.class, |
| 21 | + () -> |
| 22 | + underTest.validateOrThrow( |
| 23 | + PutPartitionerProfilesRequest.newBuilder() |
| 24 | + .addProfiles(PartitionerProfile.newBuilder().build()) |
| 25 | + .build())); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testDefaultGroupWeightIsValid() { |
| 30 | + PartitionerConfigServiceRequestValidator underTest = |
| 31 | + new PartitionerConfigServiceRequestValidator(); |
| 32 | + |
| 33 | + Exception exception = |
| 34 | + assertThrows( |
| 35 | + RuntimeException.class, |
| 36 | + () -> |
| 37 | + underTest.validateOrThrow( |
| 38 | + PutPartitionerProfilesRequest.newBuilder() |
| 39 | + .addProfiles( |
| 40 | + PartitionerProfile.newBuilder().setName("spansCountProfile").build()) |
| 41 | + .build())); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testProfilesExist() { |
| 46 | + PartitionerConfigServiceRequestValidator underTest = |
| 47 | + new PartitionerConfigServiceRequestValidator(); |
| 48 | + |
| 49 | + Exception exception = |
| 50 | + assertThrows( |
| 51 | + RuntimeException.class, |
| 52 | + () -> underTest.validateOrThrow(PutPartitionerProfilesRequest.newBuilder().build())); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testPartitionGroupsExist() { |
| 57 | + PartitionerConfigServiceRequestValidator underTest = |
| 58 | + new PartitionerConfigServiceRequestValidator(); |
| 59 | + |
| 60 | + Exception exception = |
| 61 | + assertThrows( |
| 62 | + RuntimeException.class, |
| 63 | + () -> |
| 64 | + underTest.validateOrThrow( |
| 65 | + PutPartitionerProfilesRequest.newBuilder() |
| 66 | + .addProfiles( |
| 67 | + PartitionerProfile.newBuilder() |
| 68 | + .setName("spansCountProfile") |
| 69 | + .setDefaultGroupWeight(25) |
| 70 | + .setPartitionKey("tenant_id") |
| 71 | + .build()) |
| 72 | + .build())); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testProfilePartitionKeyExists() { |
| 77 | + PartitionerConfigServiceRequestValidator underTest = |
| 78 | + new PartitionerConfigServiceRequestValidator(); |
| 79 | + |
| 80 | + Exception exception = |
| 81 | + assertThrows( |
| 82 | + RuntimeException.class, |
| 83 | + () -> |
| 84 | + underTest.validateOrThrow( |
| 85 | + PutPartitionerProfilesRequest.newBuilder() |
| 86 | + .addProfiles( |
| 87 | + PartitionerProfile.newBuilder() |
| 88 | + .setName("spansCountProfile") |
| 89 | + .setDefaultGroupWeight(25) |
| 90 | + .build()) |
| 91 | + .build())); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testPartitionGroupNameExists() { |
| 96 | + PartitionerConfigServiceRequestValidator underTest = |
| 97 | + new PartitionerConfigServiceRequestValidator(); |
| 98 | + |
| 99 | + PartitionerProfile spanCountProfile = |
| 100 | + PartitionerProfile.newBuilder() |
| 101 | + .setName("spanCountProfile") |
| 102 | + .setPartitionKey("tenantId") |
| 103 | + .setDefaultGroupWeight(35) |
| 104 | + .addAllGroups( |
| 105 | + List.of( |
| 106 | + PartitionerGroup.newBuilder() |
| 107 | + .setWeight(25) |
| 108 | + .addAllMemberIds(List.of("tenant1", "tenant2")) |
| 109 | + .build(), |
| 110 | + PartitionerGroup.newBuilder() |
| 111 | + .setName("group2") |
| 112 | + .setWeight(50) |
| 113 | + .addAllMemberIds(List.of("tenant3", "tenant4")) |
| 114 | + .build())) |
| 115 | + .build(); |
| 116 | + |
| 117 | + Exception exception = |
| 118 | + assertThrows( |
| 119 | + RuntimeException.class, |
| 120 | + () -> |
| 121 | + underTest.validateOrThrow( |
| 122 | + PutPartitionerProfilesRequest.newBuilder() |
| 123 | + .addProfiles(spanCountProfile) |
| 124 | + .build())); |
| 125 | + } |
| 126 | + |
| 127 | + @Test |
| 128 | + public void testPartitionGroupMembersExists() { |
| 129 | + PartitionerConfigServiceRequestValidator underTest = |
| 130 | + new PartitionerConfigServiceRequestValidator(); |
| 131 | + |
| 132 | + PartitionerProfile spanCountProfile = |
| 133 | + PartitionerProfile.newBuilder() |
| 134 | + .setName("spanCountProfile") |
| 135 | + .setPartitionKey("tenantId") |
| 136 | + .setDefaultGroupWeight(35) |
| 137 | + .addAllGroups( |
| 138 | + List.of( |
| 139 | + PartitionerGroup.newBuilder().setName("group1").setWeight(25).build(), |
| 140 | + PartitionerGroup.newBuilder() |
| 141 | + .setName("group2") |
| 142 | + .setWeight(50) |
| 143 | + .addAllMemberIds(List.of("tenant3", "tenant4")) |
| 144 | + .build())) |
| 145 | + .build(); |
| 146 | + |
| 147 | + Exception exception = |
| 148 | + assertThrows( |
| 149 | + RuntimeException.class, |
| 150 | + () -> |
| 151 | + underTest.validateOrThrow( |
| 152 | + PutPartitionerProfilesRequest.newBuilder() |
| 153 | + .addProfiles(spanCountProfile) |
| 154 | + .build())); |
| 155 | + } |
| 156 | + |
| 157 | + @Test |
| 158 | + public void testPartitionGroupMembersAreUniqueExists() { |
| 159 | + PartitionerConfigServiceRequestValidator underTest = |
| 160 | + new PartitionerConfigServiceRequestValidator(); |
| 161 | + |
| 162 | + PartitionerProfile spanCountProfile = |
| 163 | + PartitionerProfile.newBuilder() |
| 164 | + .setName("spanCountProfile") |
| 165 | + .setPartitionKey("tenantId") |
| 166 | + .setDefaultGroupWeight(35) |
| 167 | + .addAllGroups( |
| 168 | + List.of( |
| 169 | + PartitionerGroup.newBuilder() |
| 170 | + .setName("group1") |
| 171 | + .setWeight(25) |
| 172 | + .addAllMemberIds(List.of("tenant5", "tenant4")) |
| 173 | + .build(), |
| 174 | + PartitionerGroup.newBuilder() |
| 175 | + .setName("group2") |
| 176 | + .setWeight(50) |
| 177 | + .addAllMemberIds(List.of("tenant3", "tenant4")) |
| 178 | + .build())) |
| 179 | + .build(); |
| 180 | + |
| 181 | + Exception exception = |
| 182 | + assertThrows( |
| 183 | + RuntimeException.class, |
| 184 | + () -> |
| 185 | + underTest.validateOrThrow( |
| 186 | + PutPartitionerProfilesRequest.newBuilder() |
| 187 | + .addProfiles(spanCountProfile) |
| 188 | + .build())); |
| 189 | + } |
| 190 | +} |
0 commit comments