]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/test/netstd/Client/Performance/TestDataFactory.cs
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / test / netstd / Client / Performance / TestDataFactory.cs
1 // Licensed to the Apache Software Foundation(ASF) under one
2 // or more contributor license agreements.See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied. See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17
18 using System;
19 using System.Collections.Generic;
20 using System.Text;
21 using ThriftTest;
22 using Thrift.Collections;
23
24 namespace Client.Tests
25 {
26
27 static class TestDataFactory
28 {
29 public static CrazyNesting CreateCrazyNesting(int count = 10)
30 {
31 if (count <= 0)
32 return null;
33
34 return new CrazyNesting()
35 {
36 Binary_field = CreateBytesArray(count),
37 List_field = CreateListField(count),
38 Set_field = CreateSetField(count),
39 String_field = string.Format("data level {0}", count)
40 };
41 }
42
43 private static THashSet<Insanity> CreateSetField(int count)
44 {
45 var retval = new THashSet<Insanity>();
46 for (var i = 0; i < count; ++i)
47 retval.Add(CreateInsanity(count));
48 return retval;
49 }
50
51 private static Insanity CreateInsanity(int count)
52 {
53 return new Insanity()
54 {
55 UserMap = CreateUserMap(count),
56 Xtructs = CreateXtructs(count)
57 };
58 }
59
60 private static List<Xtruct> CreateXtructs(int count)
61 {
62 var retval = new List<Xtruct>();
63 for (var i = 0; i < count; ++i)
64 retval.Add(CreateXtruct(count));
65 return retval;
66 }
67
68 private static Xtruct CreateXtruct(int count)
69 {
70 return new Xtruct()
71 {
72 Byte_thing = (sbyte)(count % 128),
73 I32_thing = count,
74 I64_thing = count,
75 String_thing = string.Format("data level {0}", count)
76 };
77 }
78
79 private static Dictionary<Numberz, long> CreateUserMap(int count)
80 {
81 var retval = new Dictionary<Numberz, long>();
82 retval.Add(Numberz.ONE, count);
83 retval.Add(Numberz.TWO, count);
84 retval.Add(Numberz.THREE, count);
85 retval.Add(Numberz.FIVE, count);
86 retval.Add(Numberz.SIX, count);
87 retval.Add(Numberz.EIGHT, count);
88 return retval;
89 }
90
91 private static List<Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>> CreateListField(int count)
92 {
93 var retval = new List<Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>>();
94 for (var i = 0; i < count; ++i)
95 retval.Add(CreateListFieldData(count));
96 return retval;
97 }
98
99 private static Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>> CreateListFieldData(int count)
100 {
101 var retval = new Dictionary<THashSet<int>, Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>>();
102 for (var i = 0; i < count; ++i)
103 retval.Add( CreateIntHashSet(count), CreateListFieldDataDict(count));
104 return retval;
105 }
106
107 private static THashSet<int> CreateIntHashSet(int count)
108 {
109 var retval = new THashSet<int>();
110 for (var i = 0; i < count; ++i)
111 retval.Add(i);
112 return retval;
113 }
114
115 private static Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>> CreateListFieldDataDict(int count)
116 {
117 var retval = new Dictionary<int, THashSet<List<Dictionary<Insanity, string>>>>();
118 for (var i = 0; i < count; ++i)
119 retval.Add(i, CreateListFieldDataDictValue(count));
120 return retval;
121 }
122
123 private static THashSet<List<Dictionary<Insanity, string>>> CreateListFieldDataDictValue(int count)
124 {
125 var retval = new THashSet<List<Dictionary<Insanity, string>>>();
126 for (var i = 0; i < count; ++i)
127 retval.Add( CreateListFieldDataDictValueList(count));
128 return retval;
129 }
130
131 private static List<Dictionary<Insanity, string>> CreateListFieldDataDictValueList(int count)
132 {
133 var retval = new List<Dictionary<Insanity, string>>();
134 for (var i = 0; i < count; ++i)
135 retval.Add(CreateListFieldDataDictValueListDict(count));
136 return retval;
137 }
138
139 private static Dictionary<Insanity, string> CreateListFieldDataDictValueListDict(int count)
140 {
141 var retval = new Dictionary<Insanity, string>();
142 retval.Add(CreateInsanity(count), string.Format("data level {0}", count));
143 return retval;
144 }
145
146 private static byte[] CreateBytesArray(int count)
147 {
148 var retval = new byte[count];
149 for (var i = 0; i < count; ++i)
150 retval[i] = (byte)(i % 0xFF);
151 return retval;
152 }
153 }
154 }