Skip to content

Commit 293f9ea

Browse files
Add Java template changes
1 parent 4f8e4e0 commit 293f9ea

38 files changed

+182
-104
lines changed

java/src/main/java/com/example/otelstef/AnyValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public static int compare(AnyValue left, AnyValue right) {
434434
}
435435

436436
// mutateRandom mutates fields in a random, deterministic manner using random as a deterministic generator.
437-
void mutateRandom(Random random) {
437+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
438438
int fieldCount = 7;
439439
boolean typeChanged = false;
440440
if (random.nextInt(10) == 0) {
@@ -464,12 +464,12 @@ void mutateRandom(Random random) {
464464
break;
465465
case TypeArray:
466466
if (typeChanged || random.nextInt(2) == 0) {
467-
this.array.mutateRandom(random);
467+
this.array.mutateRandom(random, limiter);
468468
}
469469
break;
470470
case TypeKVList:
471471
if (typeChanged || random.nextInt(2) == 0) {
472-
this.kVList.mutateRandom(random);
472+
this.kVList.mutateRandom(random, limiter);
473473
}
474474
break;
475475
case TypeBytes:

java/src/main/java/com/example/otelstef/AnyValueArray.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,20 @@ public static int compare(AnyValueArray left, AnyValueArray right) {
204204

205205
// mutateRandom mutates fields in a random, deterministic manner using
206206
// random parameter as a deterministic generator.
207-
void mutateRandom(Random random) {
207+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
208208
if (random.nextInt(20) == 0) {
209-
ensureLen(len() + 1);
209+
if (limiter.elemCount < CommonMutateRandomLimiter.maxElems) {
210+
ensureLen(len() + 1);
211+
limiter.elemCount++;
212+
}
210213
}
211214
if (random.nextInt(20) == 0 && len() > 0) {
212215
ensureLen(len() - 1);
213216
}
214217
for (int i = 0; i < elemsLen; i++) {
215218
if (random.nextInt(2 * elemsLen) == 0) {
216219

217-
elems[i].mutateRandom(random);
220+
elems[i].mutateRandom(random, limiter);
218221

219222
}
220223
}

java/src/main/java/com/example/otelstef/Attributes.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,12 @@ public static int compare(Attributes left, Attributes right) {
215215
}
216216

217217
// mutateRandom mutates fields in a random, deterministic manner using random parameter as a deterministic generator.
218-
void mutateRandom(Random random) {
218+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
219219
if (random.nextInt(20) == 0) {
220-
ensureLen(elemsLen + 1);
220+
if (limiter.elemCount < CommonMutateRandomLimiter.maxElems) {
221+
ensureLen(elemsLen + 1);
222+
limiter.elemCount++;
223+
}
221224
}
222225
if (random.nextInt(20) == 0 && elemsLen > 0) {
223226
ensureLen(elemsLen - 1);
@@ -227,7 +230,7 @@ void mutateRandom(Random random) {
227230
setKey(i, Types.StringRandom(random));
228231
}
229232
if (random.nextInt(4 * elemsLen) == 0) {
230-
elems[i].value.mutateRandom(random);
233+
elems[i].value.mutateRandom(random, limiter);
231234
}
232235
}
233236
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Code generated by stefc. DO NOT EDIT.
2+
package com.example.otelstef;
3+
4+
// CommonMutateRandomLimiter is used to track and limit the total number of objects and elements
5+
// created during a mutateRandom call.
6+
class CommonMutateRandomLimiter {
7+
int objectCount;
8+
int elemCount;
9+
10+
// Maximum number of objects to create per mutateRandom call.
11+
static int maxObjects = 100;
12+
13+
// Maximum number of array or multimap elements to create per mutateRandom call.
14+
static int maxElems = 100;
15+
}

java/src/main/java/com/example/otelstef/Envelope.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ public static int compare(Envelope left, Envelope right) {
135135
}
136136

137137
// mutateRandom mutates fields in a random, deterministic manner using random as a deterministic generator.
138-
void mutateRandom(Random random) {
138+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
139139
final int fieldCount = Math.max(1,2); // At least 2 to ensure we don't recurse infinitely if there is only 1 field.
140140

141141
if (random.nextInt(fieldCount) == 0) {
142-
this.attributes.mutateRandom(random);
142+
this.attributes.mutateRandom(random, limiter);
143143
}
144144

145145
}

java/src/main/java/com/example/otelstef/EnvelopeAttributes.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,12 @@ public static int compare(EnvelopeAttributes left, EnvelopeAttributes right) {
220220
}
221221

222222
// mutateRandom mutates fields in a random, deterministic manner using random parameter as a deterministic generator.
223-
void mutateRandom(Random random) {
223+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
224224
if (random.nextInt(20) == 0) {
225-
ensureLen(elemsLen + 1);
225+
if (limiter.elemCount < CommonMutateRandomLimiter.maxElems) {
226+
ensureLen(elemsLen + 1);
227+
limiter.elemCount++;
228+
}
226229
}
227230
if (random.nextInt(20) == 0 && elemsLen > 0) {
228231
ensureLen(elemsLen - 1);

java/src/main/java/com/example/otelstef/Event.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ public static int compare(Event left, Event right) {
261261
}
262262

263263
// mutateRandom mutates fields in a random, deterministic manner using random as a deterministic generator.
264-
void mutateRandom(Random random) {
264+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
265265
final int fieldCount = Math.max(4,2); // At least 2 to ensure we don't recurse infinitely if there is only 1 field.
266266

267267
if (random.nextInt(fieldCount) == 0) {
@@ -273,7 +273,7 @@ void mutateRandom(Random random) {
273273
}
274274

275275
if (random.nextInt(fieldCount) == 0) {
276-
this.attributes.mutateRandom(random);
276+
this.attributes.mutateRandom(random, limiter);
277277
}
278278

279279
if (random.nextInt(fieldCount) == 0) {

java/src/main/java/com/example/otelstef/EventArray.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,20 @@ public static int compare(EventArray left, EventArray right) {
204204

205205
// mutateRandom mutates fields in a random, deterministic manner using
206206
// random parameter as a deterministic generator.
207-
void mutateRandom(Random random) {
207+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
208208
if (random.nextInt(20) == 0) {
209-
ensureLen(len() + 1);
209+
if (limiter.elemCount < CommonMutateRandomLimiter.maxElems) {
210+
ensureLen(len() + 1);
211+
limiter.elemCount++;
212+
}
210213
}
211214
if (random.nextInt(20) == 0 && len() > 0) {
212215
ensureLen(len() - 1);
213216
}
214217
for (int i = 0; i < elemsLen; i++) {
215218
if (random.nextInt(2 * elemsLen) == 0) {
216219

217-
elems[i].mutateRandom(random);
220+
elems[i].mutateRandom(random, limiter);
218221

219222
}
220223
}

java/src/main/java/com/example/otelstef/Exemplar.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ public static int compare(Exemplar left, Exemplar right) {
301301
}
302302

303303
// mutateRandom mutates fields in a random, deterministic manner using random as a deterministic generator.
304-
void mutateRandom(Random random) {
304+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
305305
final int fieldCount = Math.max(5,2); // At least 2 to ensure we don't recurse infinitely if there is only 1 field.
306306

307307
if (random.nextInt(fieldCount) == 0) {
308308
this.setTimestamp(Types.Uint64Random(random));
309309
}
310310

311311
if (random.nextInt(fieldCount) == 0) {
312-
this.value.mutateRandom(random);
312+
this.value.mutateRandom(random, limiter);
313313
}
314314

315315
if (random.nextInt(fieldCount) == 0) {
@@ -321,7 +321,7 @@ void mutateRandom(Random random) {
321321
}
322322

323323
if (random.nextInt(fieldCount) == 0) {
324-
this.filteredAttributes.mutateRandom(random);
324+
this.filteredAttributes.mutateRandom(random, limiter);
325325
}
326326

327327
}

java/src/main/java/com/example/otelstef/ExemplarArray.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,17 +204,20 @@ public static int compare(ExemplarArray left, ExemplarArray right) {
204204

205205
// mutateRandom mutates fields in a random, deterministic manner using
206206
// random parameter as a deterministic generator.
207-
void mutateRandom(Random random) {
207+
void mutateRandom(Random random, CommonMutateRandomLimiter limiter) {
208208
if (random.nextInt(20) == 0) {
209-
ensureLen(len() + 1);
209+
if (limiter.elemCount < CommonMutateRandomLimiter.maxElems) {
210+
ensureLen(len() + 1);
211+
limiter.elemCount++;
212+
}
210213
}
211214
if (random.nextInt(20) == 0 && len() > 0) {
212215
ensureLen(len() - 1);
213216
}
214217
for (int i = 0; i < elemsLen; i++) {
215218
if (random.nextInt(2 * elemsLen) == 0) {
216219

217-
elems[i].mutateRandom(random);
220+
elems[i].mutateRandom(random, limiter);
218221

219222
}
220223
}

0 commit comments

Comments
 (0)