Exemple #1
0
 internal static void randomCar(Common.FastRand rng, CarSalesSchema.Car.Builder car)
 {
     car.SetMake(MAKES[rng.nextLessThan(MAKES.Length)]);
     car.SetModel(MODELS[rng.nextLessThan(MODELS.Length)]);
     car.SetColor(colors[rng.nextLessThan((short)CarSalesSchema.Color.Silver + 1)]);
     car.SetSeats(unchecked ((byte)(2 + rng.nextLessThan(6))));
     car.SetDoors(unchecked ((byte)(2 + rng.nextLessThan(3))));
     foreach (CarSalesSchema.Wheel.Builder wheel in car.InitWheels(4))
     {
         wheel.SetDiameter((ushort)(25 + rng.nextLessThan(15)));
         wheel.SetAirPressure((float)(30.0 + rng.nextDouble(20.0)));
         wheel.SetSnowTires(rng.nextLessThan(16) == 0);
     }
     car.SetLength((ushort)(170 + rng.nextLessThan(150)));
     car.SetWidth((ushort)(48 + rng.nextLessThan(36)));
     car.SetHeight((ushort)(54 + rng.nextLessThan(48)));
     car.SetWeight((uint)car.GetLength() * (uint)car.GetWidth() * (uint)car.GetHeight() / 200);
     CarSalesSchema.Engine.Builder engine = car.InitEngine();
     engine.SetHorsepower((ushort)(100 * rng.nextLessThan(400)));
     engine.SetCylinders(unchecked ((byte)(4 + 2 * rng.nextLessThan(3))));
     engine.SetCc((uint)(800 + rng.nextLessThan(10000)));
     engine.SetUsesGas(true);
     engine.SetUsesElectric(rng.nextLessThan(2) == 1);
     car.SetFuelCapacity((float)(10.0 + rng.nextDouble(30.0)));
     car.SetFuelLevel((float)(rng.nextDouble(car.GetFuelCapacity())));
     car.SetHasPowerWindows(rng.nextLessThan(2) == 1);
     car.SetHasPowerSteering(rng.nextLessThan(2) == 1);
     car.SetHasCruiseControl(rng.nextLessThan(2) == 1);
     car.SetCupHolders(unchecked ((byte)rng.nextLessThan(12)));
     car.SetHasNavSystem(rng.nextLessThan(2) == 1);
 }
Exemple #2
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void passByBytes(RequestFactory requestFactory, ResponseFactory responseFactory, Compression compression, long iters)
 {
     java.nio.ByteBuffer requestBytes  = java.nio.ByteBuffer.allocate(SCRATCH_SIZE * 8);
     java.nio.ByteBuffer responseBytes = java.nio.ByteBuffer.allocate(SCRATCH_SIZE * 8);
     Common.FastRand     rng           = new Common.FastRand();
     for (int i = 0; i < iters; ++i)
     {
         MessageBuilder  requestMessage  = new MessageBuilder();
         MessageBuilder  responseMessage = new MessageBuilder();
         RequestBuilder  request         = requestMessage.InitRoot(requestFactory);
         Expectation     expected        = this.setupRequest(rng, request);
         ResponseBuilder response        = responseMessage.InitRoot(responseFactory);
         {
             ArrayOutputStream writer = new ArrayOutputStream(requestBytes);
             compression.writeBuffered(writer, requestMessage);
         }
         {
             MessageReader messageReader = compression.newBufferedReader(new ArrayInputStream(requestBytes));
             this.handleRequest(messageReader.GetRoot(requestFactory), response);
         }
         {
             ArrayOutputStream writer = new ArrayOutputStream(responseBytes);
             compression.writeBuffered(writer, responseMessage);
         }
         {
             MessageReader messageReader = compression.newBufferedReader(new ArrayInputStream(responseBytes));
             if (!this.checkResponse(messageReader.GetRoot(responseFactory), expected))
             {
                 throw new System.Exception("incorrect response");
             }
         }
     }
 }
Exemple #3
0
        public sealed override ulong setupRequest(Common.FastRand rng, CarSalesSchema.ParkingLot.Builder request)
        {
            ulong result = 0;

            StructList.Builder <CarSalesSchema.Car.Builder> cars = request.InitCars(rng.nextLessThan(200));
            for (int i = 0; i < cars.Length; ++i)
            {
                CarSalesSchema.Car.Builder car = cars.Get(i);
                randomCar(rng, car);
                result += carValue(car.AsReader());
            }
            return(result);
        }
Exemple #4
0
        public static int makeExpression(Common.FastRand rng, EvalSchema.Expression.Builder exp, int depth)
        {
            exp.SetOp(operations[rng.nextLessThan((short)EvalSchema.Operation.Modulus + 1)]);
            int left = 0;

            if (rng.nextLessThan(8) < depth)
            {
                int tmp = rng.nextLessThan(128) + 1;
                exp.GetLeft().SetValue(tmp);
                left = tmp;
            }
            else
            {
                left = makeExpression(rng, exp.GetLeft().InitExpression(), depth + 1);
            }
            int right = 0;

            if (rng.nextLessThan(8) < depth)
            {
                int tmp = rng.nextLessThan(128) + 1;
                exp.GetRight().SetValue(tmp);
                right = tmp;
            }
            else
            {
                right = makeExpression(rng, exp.GetRight().InitExpression(), depth + 1);
            }

            switch ((short)exp.GetOp())
            {
            case 0:
                return(left + right);

            case 1:
                return(left - right);

            case 2:
                return(left * right);

            case 3:
                return(Common.div(left, right));

            case 4:
                return(Common.modulus(left, right));

            default:
                throw new System.Exception("impossible");
            }
        }
Exemple #5
0
        public override int setupRequest(Common.FastRand rng, CatRankSchema.SearchResultList.Builder request)
        {
            int count     = rng.nextLessThan(1000);
            int goodCount = 0;

            StructList.Builder <CatRankSchema.SearchResult.Builder> list = request.InitResults(count);
            for (int i = 0; i < list.Length; ++i)
            {
                CatRankSchema.SearchResult.Builder result = list.Get(i);
                result.SetScore(1000.0 - (double)i);
                int                 urlSize         = rng.nextLessThan(100);
                int                 urlPrefixLength = URL_PREFIX.Length;
                Text.Builder        url             = result.InitUrl(urlSize + urlPrefixLength);
                java.nio.ByteBuffer bytes           = url.asByteBuffer();
                bytes.put(URL_PREFIX.asByteBuffer());
                for (int j = 0; j < urlSize; j++)
                {
                    bytes.put(unchecked ((byte)(97 + rng.nextLessThan(26))));
                }
                bool isCat = rng.nextLessThan(8) == 0;
                bool isDog = rng.nextLessThan(8) == 0;
                if (isCat && !isDog)
                {
                    goodCount += 1;
                }
                System.Text.StringBuilder snippet = new System.Text.StringBuilder(" ");
                int prefix = rng.nextLessThan(20);
                for (int j = 0; j < prefix; ++j)
                {
                    snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]);
                }
                if (isCat)
                {
                    snippet.Append("cat ");
                }
                if (isDog)
                {
                    snippet.Append("dog ");
                }
                int suffix = rng.nextLessThan(20);
                for (int j = 0; j < suffix; ++j)
                {
                    snippet.Append(Common.WORDS[rng.nextLessThan(Common.WORDS.Length)]);
                }
                result.SetSnippet(snippet.ToString());
            }
            return(goodCount);
        }
Exemple #6
0
 public virtual void passByObject(RequestFactory requestFactory, ResponseFactory responseFactory, Compression compression, long iters)
 {
     Common.FastRand rng = new Common.FastRand();
     for (int i = 0; i < iters; ++i)
     {
         MessageBuilder  requestMessage  = new MessageBuilder();
         MessageBuilder  responseMessage = new MessageBuilder();
         RequestBuilder  request         = requestMessage.InitRoot(requestFactory);
         Expectation     expected        = this.setupRequest(rng, request);
         ResponseBuilder response        = responseMessage.InitRoot(responseFactory);
         this.handleRequest(requestFactory.AsReader(request), response);
         if (!this.checkResponse(responseFactory.AsReader(response), expected))
         {
             System.Console.Out.WriteLine("mismatch!");
         }
     }
 }
Exemple #7
0
        /// <exception cref="System.IO.IOException"/>
        public virtual void syncClient(RequestFactory requestFactory, ResponseFactory responseFactory, Compression compression, long iters)
        {
            Common.FastRand             rng         = new Common.FastRand();
            BufferedOutputStreamWrapper outBuffered = new BufferedOutputStreamWrapper(new FileDescriptor(Console.OpenStandardOutput()));
            BufferedInputStreamWrapper  inBuffered  = new BufferedInputStreamWrapper(new FileDescriptor(Console.OpenStandardInput()));

            for (int ii = 0; ii < iters; ++ii)
            {
                MessageBuilder requestMessage = new MessageBuilder();
                RequestBuilder request        = requestMessage.InitRoot(requestFactory);
                Expectation    expected       = this.setupRequest(rng, request);
                compression.writeBuffered(outBuffered, requestMessage);
                MessageReader  messageReader = compression.newBufferedReader(inBuffered);
                ResponseReader response      = messageReader.GetRoot(responseFactory);
                if (!this.checkResponse(response, expected))
                {
                    throw new System.Exception("incorrect response");
                }
            }
        }
Exemple #8
0
 public sealed override int setupRequest(Common.FastRand rng, EvalSchema.Expression.Builder request)
 {
     return(makeExpression(rng, request, 0));
 }
Exemple #9
0
 public abstract Expectation setupRequest(Common.FastRand rng, RequestBuilder request);